字串過濾器

字串過濾器

每個過濾器都正如其名字暗示的那樣工作並與內建的 PHP 字串函式的行為相對應。對於指定過濾器的更多資訊,請參考該函式的手冊頁。

string.rot13

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

示例 #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() 函式處理所有的流數據。

示例 #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() 函式處理所有的流數據。

示例 #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() 函式處理所有的流數據。可以用兩種格式接收參數:一種是和 strip_tags() 函式第二個參數相似的一個包含有標記列表的字串,一種是一個包含有標記名的陣列。

警告

本特性已自 PHP 7.3.0 起廢棄。強烈建議不要使用本特性。

示例 #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   */
?>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *