PHP Portal » PHP Handbuch » String Filters

Werbung

String Filters


Each of these filters does precisely what their name implies and correspond to the behavior of a built-in php string handling function. For more information on a given filter, refer to the manual page for the corresponding function.

string.rot13 (since PHP 4.3.0) Use of this filter is equivalent to processing all stream data through the str_rot13() function.

PHP Code
1
2
3
4
$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 (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the strtoupper() function.

PHP Code
1
2
3
4
$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 (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the strtolower() function.

PHP Code
1
2
3
4
$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 (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the strip_tags() function. It accepts parameters in one of two forms: Either as a string containing a list of tags similar to the second parameter of the strip_tags() function, or as an array of tag names.

PHP Code
1
2
3
4
5
6
7
8
9
10
$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 */