字符串過濾器

每個(gè)過濾器都正如其名字暗示的那樣工作并與內(nèi)置的 PHP 字符串函數(shù)的行為相對應(yīng)。對于指定過濾器的更多信息,請參考該函數(shù)的手冊頁。

string.rot13

使用該過濾器也就是用 str_rot13() 函數(shù)處理所有的流數(shù)據(jù)。

示例 #1 string.rot13

<?php
$fp 
fopen('php://output''w');
stream_filter_append($fp'string.rot13');
fwrite($fp"This is a test.\n");
/* 輸出: Guvf vf n grfg.   */
?>

string.toupper

使用此過濾器等同于用 strtoupper() 函數(shù)處理所有的流數(shù)據(jù)。

示例 #2 string.toupper

<?php
$fp 
fopen('php://output''w');
stream_filter_append($fp'string.toupper');
fwrite($fp"This is a test.\n");
/* 輸出: THIS IS A TEST.   */
?>

string.tolower

使用此過濾器等同于用 strtolower() 函數(shù)處理所有的流數(shù)據(jù)。

示例 #3 string.tolower

<?php
$fp 
fopen('php://output''w');
stream_filter_append($fp'string.tolower');
fwrite($fp"This is a test.\n");
/* 輸出: this is a test.   */
?>

string.strip_tags

使用此過濾器等同于用 strip_tags() 函數(shù)處理所有的流數(shù)據(jù)。可以用兩種格式接收參數(shù):一種是和 strip_tags() 函數(shù)第二個(gè)參數(shù)相似的一個(gè)包含有標(biāo)記列表的字符串,一種是一個(gè)包含有標(biāo)記名的數(shù)組。

警告

本特性已自 PHP 7.3.0 起廢棄。強(qiáng)烈建議不要使用本特性。

示例 #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);
/* 輸出: <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);
/* 輸出: <b>bolded text</b> enlarged to a level 1 heading   */
?>