字符串过滤器

每个过滤器都正如其名字暗示的那样工作并与内置的 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);
/* 输出: bolded text 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);
/* 输出: bolded text enlarged to a level 1 heading */
?>
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top