轉換過濾器

如同 string.* 過濾器,convert.* 過濾器的作用就和其名字一樣。轉換過濾器是 PHP 5.0.0 增加的。對於指定過濾器的更多訊息,請參考該函數的手冊頁。

convert.base64-encodeconvert.base64-decode 使用這兩個過濾器等同於分別用 base64_encode()base64_decode() 函數處理所有的流資料。convert.base64-encode 支援以一個關聯陣列給出的參數。若果給出了 line-length,base64 輸出將被用 line-length 個字元為 長度而截成塊。若果給出了 line-break-chars,每塊將被用給出的字元隔開。這些參數的效果和用 base64_encode() 再加上 chunk_split() 相同。

例子 N-5. convert.base64-encode & convert.base64-decode

<?php
$fp 
fopen('php://output''w');
stream_filter_append($fp'convert.base64-encode');
fwrite($fp"This is a test.\n");
fclose($fp);
/* Outputs:  VGhpcyBpcyBhIHRlc3QuCg==  */

$param = array('line-length' => 8'line-break-chars' => "\r\n");
$fp fopen('php://output''w');
stream_filter_append($fp'convert.base64-encode'STREAM_FILTER_WRITE$param);
fwrite($fp"This is a test.\n");
fclose($fp);
/* Outputs:  VGhpcyBp
          :  cyBhIHRl
          :  c3QuCg==  */

$fp fopen('php://output''w');
stream_filter_append($fp'convert.base64-decode');
fwrite($fp"VGhpcyBpcyBhIHRlc3QuCg==");
fclose($fp);
/* Outputs:  This is a test.  */
?>

convert.quoted-printable-encodeconvert.quoted-printable-decode 使用此過濾器的 decode 版本等同於用 quoted_printable_decode() 函數處理所有的流資料。沒有和 convert.quoted-printable-encode 相對應的函數。convert.quoted-printable-encode 支援以一個關聯陣列給出的參數。除了支援和 convert.base64-encode 一樣的附加參數外,convert.quoted-printable-encode 還支援布爾參數 binaryforce-encode-firstconvert.base64-decode 只支援 line-break-chars 參數作為從編碼載荷中剝離的類型提示。

例子 N-6. convert.quoted-printable-encode & convert.quoted-printable-decode

<?php
$fp 
fopen('php://output''w');
stream_filter_append($fp'convert.quoted-printable-encode');
fwrite($fp"This is a test.\n");
/* Outputs:  =This is a test.=0A  */
?>