|
下面列出了用在 stream_filter_append()
中的幾個內建的流過濾器。會員的 PHP 版本中的過濾器也許比這裡列出的更多(或更少)。
值得指出 stream_filter_append()
與 stream_filter_prepend()
之間有少許不平衡。每個 PHP
流都含有一個小的讀取緩沖區,它存儲了來自檔案系統或其它資源的幾段資料以便更有效率地處理。資料一從資源進入流的內定緩沖區,立刻被附上的過濾器處理而不管
PHP 程式是否真的已經準備好接收資料。當過濾器是
appended
時若果資料等待在讀取緩沖區,資料將被立即通過過濾器處理,使其效果看上去是透明的。然而當過濾器是
prepended
時若果資料等待在讀取緩沖區,資料將不會被該過濾器處理。該資料將會等到從資源取得下一段資料後才會被處理。
用 stream_get_filters() 來列出 PHP 中已安裝的過濾器。
每個過濾器都正如其名字暗示的那樣工作並與內建的
PHP 字串函數的行為相對應。對於指定過濾器的更多訊息,請參考該函數的手冊頁。
string.rot13(自
PHP 4.3.0 起)使用此過濾器等同於用
str_rot13() 函數處理所有的流資料。
例子 N-1. string.rot13
<?php $fp = fopen('php://output', 'w'); stream_filter_append($fp, 'string.rot13'); fwrite($fp, "This is a test.\n"); /* Outputs: Guvf vf n grfg. */ ?>
|
|
string.toupper(自
PHP 5.0.0 起)使用此過濾器等同於用
strtoupper() 函數處理所有的流資料。
例子 N-2. string.toupper
<?php $fp = fopen('php://output', 'w'); stream_filter_append($fp, 'string.toupper'); fwrite($fp, "This is a test.\n"); /* Outputs: THIS IS A TEST. */ ?>
|
|
string.tolower(自
PHP 5.0.0 起)使用此過濾器等同於用
strtolower() 函數處理所有的流資料。
例子 N-3. string.tolower
<?php $fp = fopen('php://output', 'w'); stream_filter_append($fp, 'string.tolower'); fwrite($fp, "This is a test.\n"); /* Outputs: this is a test. */ ?>
|
|
string.strip_tags(自
PHP 5.0.0 起)使用此過濾器等同於用
strip_tags()
函數處理所有的流資料。可以用兩種格式接收參數:一種是和
strip_tags()
函數第二個參數相似的一個包括有旗標清單的字串,一種是一個包括有旗標名的陣列。
例子 N-4. string.strip_tags
<?php $fp = fopen('php://output', 'w'); stream_filter_append($fp, 'string.strip_tags', STREAM_FILTER_WRITE, "<b><i><u>"); fwrite($fp, "<b>bolded text</b> enlarged to a <h1>level 1 heading</h1>\n"); fclose($fp); /* Outputs: <b>bolded text</b> enlarged to a level 1 heading */
$fp = fopen('php://output', 'w'); stream_filter_append($fp, 'string.strip_tags', STREAM_FILTER_WRITE, array('b','i','u')); fwrite($fp, "<b>bolded text</b> enlarged to a <h1>level 1 heading</h1>\n"); fclose($fp); /* Outputs: <b>bolded text</b> enlarged to a level 1 heading */ ?>
|
|
| |