<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>String Filters</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="filters.html">List of Available Filters</a></div> <div class="next" style="text-align: right; float: right;"><a href="filters.convert.html">Conversion Filters</a></div> <div class="up"><a href="filters.html">List of Available Filters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="filters.string" class="section"> <h2 class="title">String Filters</h2> <p class="simpara"> 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. </p> <p class="simpara"> <em>string.rot13</em> (since PHP 4.3.0) Use of this filter is equivalent to processing all stream data through the <span class="function"><a href="function.str-rot13.html" class="function">str_rot13()</a></span> function. </p> <div class="example" id="example-5630"> <p><strong>Example #1 string.rot13</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'string.rot13'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"This is a test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs: Guvf vf n grfg. */<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <p class="simpara"> <em>string.toupper</em> (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the <span class="function"><a href="function.strtoupper.html" class="function">strtoupper()</a></span> function. </p> <div class="example" id="example-5631"> <p><strong>Example #2 string.toupper</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'string.toupper'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"This is a test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs: THIS IS A TEST. */<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <p class="simpara"> <em>string.tolower</em> (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the <span class="function"><a href="function.strtolower.html" class="function">strtolower()</a></span> function. </p> <div class="example" id="example-5632"> <p><strong>Example #3 string.tolower</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'string.tolower'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"This is a test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs: this is a test. */<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <p class="simpara"> <em>string.strip_tags</em> (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the <span class="function"><a href="function.strip-tags.html" class="function">strip_tags()</a></span> 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 <span class="function"><a href="function.strip-tags.html" class="function">strip_tags()</a></span> function, or as an array of tag names. </p> <div class="example" id="example-5633"> <p><strong>Example #4 string.strip_tags</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'string.strip_tags'</span><span style="color: #007700">, </span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">, </span><span style="color: #DD0000">"<b><i><u>"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"<b>bolded text</b> enlarged to a <h1>level 1 heading</h1>\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs: <b>bolded text</b> enlarged to a level 1 heading */<br /><br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'string.strip_tags'</span><span style="color: #007700">, </span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">, array(</span><span style="color: #DD0000">'b'</span><span style="color: #007700">,</span><span style="color: #DD0000">'i'</span><span style="color: #007700">,</span><span style="color: #DD0000">'u'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"<b>bolded text</b> enlarged to a <h1>level 1 heading</h1>\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs: <b>bolded text</b> enlarged to a level 1 heading */<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="filters.html">List of Available Filters</a></div> <div class="next" style="text-align: right; float: right;"><a href="filters.convert.html">Conversion Filters</a></div> <div class="up"><a href="filters.html">List of Available Filters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>