filters.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 146 行

HTML
146
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>List of Available Filters</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="wrappers.expect.html">Process Interaction Streams</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="appendices.html">Appendices</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1>List of Available Filters</h1><h2>Table of Contents</h2><ul class="chunklist chunklist_appendix"><li><a href="filters.convert.html">Conversion Filters</a></li><li><a href="filters.compression.html">Compression Filters</a></li><li><a href="filters.encryption.html">Encryption Filters</a></li></ul> <p class="para">  The following is a list of a few built-in stream filters for  use with <a href="function.stream-filter-append.html" class="function">stream_filter_append()</a>.  Your version of PHP may have more filters (or fewer) than those  listed here. </p> <p class="para">  It is worth noting a slight asymmetry between   <a href="function.stream-filter-append.html" class="function">stream_filter_append()</a>  and <a href="function.stream-filter-prepend.html" class="function">stream_filter_prepend()</a>.    Every PHP stream contains a small <em class="emphasis">read buffer</em>  where it stores blocks of data retrieved from the  filesystem or other resource in order to process data  in the most efficient manner.  As soon as data is pulled  from the resource into the stream&#039;s internal buffer, it  is immediately processed through any attached filters whether  the PHP application is actually ready for the data or not.  If data is sitting in the read buffer when a filter is   <em class="emphasis">appended</em>, this data will be immediately  processed through that filter making the fact that it was  sitting in the buffer seem transparent.  However, if data is  sitting in the read buffer when a filter is   <em class="emphasis">prepended</em>, this data will <em class="emphasis">NOT</em>  be processed through that filter.  It will instead wait until  the next block of data is retrieved from the resource. </p> <p class="para">  For a list of filters installed in your version of  PHP use <a href="function.stream-get-filters.html" class="function">stream_get_filters()</a>. </p> <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">   <i>string.rot13</i>   (since PHP 4.3.0)   Use of this filter is equivalent to processing all stream data through   the <a href="function.str-rot13.html" class="function">str_rot13()</a> function.  </p>  <div class="example">   <p><b>Example #1 string.rot13</b></p>   <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</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">,&nbsp;</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">,&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;a&nbsp;test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Outputs:&nbsp;&nbsp;Guvf&nbsp;vf&nbsp;n&nbsp;grfg.&nbsp;&nbsp;&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>   </div>  </div>  <p class="simpara">   <i>string.toupper</i>   (since PHP 5.0.0)   Use of this filter is equivalent to processing all stream data through   the <a href="function.strtoupper.html" class="function">strtoupper()</a> function.  </p>  <div class="example">   <p><b>Example #2 string.toupper</b></p>   <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</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">,&nbsp;</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">,&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;a&nbsp;test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Outputs:&nbsp;&nbsp;THIS&nbsp;IS&nbsp;A&nbsp;TEST.&nbsp;&nbsp;&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>   </div>  </div>  <p class="simpara">   <i>string.tolower</i>   (since PHP 5.0.0)   Use of this filter is equivalent to processing all stream data through   the <a href="function.strtolower.html" class="function">strtolower()</a> function.  </p>  <div class="example">   <p><b>Example #3 string.tolower</b></p>   <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</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">,&nbsp;</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">,&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;a&nbsp;test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Outputs:&nbsp;&nbsp;this&nbsp;is&nbsp;a&nbsp;test.&nbsp;&nbsp;&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>   </div>  </div>  <p class="simpara">   <i>string.strip_tags</i>   (since PHP 5.0.0)   Use of this filter is equivalent to processing all stream data through   the <a href="function.strip-tags.html" class="function">strip_tags()</a> 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 <a href="function.strip-tags.html" class="function">strip_tags()</a> function,   or as an array of tag names.  </p>  <div class="example">   <p><b>Example #4 string.strip_tags</b></p>   <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</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">,&nbsp;</span><span style="color: #DD0000">'string.strip_tags'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&lt;b&gt;&lt;i&gt;&lt;u&gt;"</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">,&nbsp;</span><span style="color: #DD0000">"&lt;b&gt;bolded&nbsp;text&lt;/b&gt;&nbsp;enlarged&nbsp;to&nbsp;a&nbsp;&lt;h1&gt;level&nbsp;1&nbsp;heading&lt;/h1&gt;\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">/*&nbsp;Outputs:&nbsp;&nbsp;&lt;b&gt;bolded&nbsp;text&lt;/b&gt;&nbsp;enlarged&nbsp;to&nbsp;a&nbsp;level&nbsp;1&nbsp;heading&nbsp;&nbsp;&nbsp;*/<br /><br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</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">,&nbsp;</span><span style="color: #DD0000">'string.strip_tags'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">,&nbsp;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">,&nbsp;</span><span style="color: #DD0000">"&lt;b&gt;bolded&nbsp;text&lt;/b&gt;&nbsp;enlarged&nbsp;to&nbsp;a&nbsp;&lt;h1&gt;level&nbsp;1&nbsp;heading&lt;/h1&gt;\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">/*&nbsp;Outputs:&nbsp;&nbsp;&lt;b&gt;bolded&nbsp;text&lt;/b&gt;&nbsp;enlarged&nbsp;to&nbsp;a&nbsp;level&nbsp;1&nbsp;heading&nbsp;&nbsp;&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>   </div>  </div>    </div>   </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="wrappers.expect.html">Process Interaction Streams</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="appendices.html">Appendices</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?