文字

字符串过滤器

每个过滤器都正如其名字暗示的那样工作并与内置的 PHP 字符串函数的行为相对应。对于指定过滤器的更多信息,请参考该函数的手册页。

string.rot13(自 PHP 4.3.0 起)使用此过滤器等同于用 str_rot13() 函数处理所有的流数据。

Example #1 string.rot13

<?php
$fp 
fopen ( 'php://output' 'w' );
stream_filter_append ( $fp 'string.rot13' );
fwrite ( $fp "This is a test.\n" );

?>

string.toupper(自 PHP 5.0.0 起)使用此过滤器等同于用 strtoupper() 函数处理所有的流数据。

Example #2 string.toupper

<?php
$fp 
fopen ( 'php://output' 'w' );
stream_filter_append ( $fp 'string.toupper' );
fwrite ( $fp "This is a test.\n" );

?>

string.tolower(自 PHP 5.0.0 起)使用此过滤器等同于用 strtolower() 函数处理所有的流数据。

Example #3 string.tolower

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

?>

string.strip_tags(自 PHP 5.0.0 起)使用此过滤器等同于用 strip_tags() 函数处理所有的流数据。可以用两种格式接收参数:一种是和 strip_tags() 函数第二个参数相似的一个包含有标记列表的字符串,一种是一个包含有标记名的数组。

Example #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 );


$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 );

?>
上一篇: 下一篇: