⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.stream-filter-append.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Attach a filter to a stream</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="function.stream-encoding.html">stream_encoding</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stream-filter-prepend.html">stream_filter_prepend</a></div> <div class="up"><a href="ref.stream.html">Stream Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.stream-filter-append" class="refentry"> <div class="refnamediv">  <h1 class="refname">stream_filter_append</h1>  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">stream_filter_append</span> &mdash; <span class="dc-title">Attach a filter to a stream</span></p> </div> <div class="refsect1 unknown">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">resource</span> <span class="methodname"><b><b>stream_filter_append</b></b></span>    ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$stream</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$filtername</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$read_write</tt></span>   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$params</tt></span>  ]] )</div>  <p class="para rdfs-comment">   Adds <i><tt class="parameter">filtername</tt></i> to the list of filters   attached to <i><tt class="parameter">stream</tt></i>.  This filter will be   added with the specified <i><tt class="parameter">params</tt></i>   to the <em class="emphasis">end</em> of the list and   will therefore be called last during stream operations.  To   add a filter to the beginning of the list, use   <a href="function.stream-filter-prepend.html" class="function">stream_filter_prepend()</a>.  </p>  <p class="para">   By default, <b>stream_filter_append()</b> will   attach the filter to the <i>read filter chain</i>   if the file was opened for reading (i.e. File Mode:   <i>r</i>, and/or <i>+</i>).  The filter   will also be attached to the <i>write filter chain</i>   if the file was opened for writing (i.e. File Mode:   <i>w</i>, <i>a</i>, and/or <i>+</i>).   <b><tt>STREAM_FILTER_READ</tt></b>,   <b><tt>STREAM_FILTER_WRITE</tt></b>, and/or   <b><tt>STREAM_FILTER_ALL</tt></b> can also be passed to the   <i><tt class="parameter">read_write</tt></i> parameter to override this behavior.  </p>  <p class="para">   As of PHP 5.1.0, this function returns a resource which   can be used to refer to this filter instance during a call   to <a href="function.stream-filter-remove.html" class="function">stream_filter_remove()</a>.   Prior to PHP 5.1.0, this function returns <b><tt>TRUE</tt></b> on success   or <b><tt>FALSE</tt></b> on failure.  </p>  <p class="para">   <div class="example">    <p><b>Example #1 Controlling where filters are applied</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Open&nbsp;a&nbsp;test&nbsp;file&nbsp;for&nbsp;reading&nbsp;and&nbsp;writing&nbsp;*/<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">'test.txt'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w+'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Apply&nbsp;the&nbsp;ROT13&nbsp;filter&nbsp;to&nbsp;the<br />&nbsp;*&nbsp;write&nbsp;filter&nbsp;chain,&nbsp;but&nbsp;not&nbsp;the<br />&nbsp;*&nbsp;read&nbsp;filter&nbsp;chain&nbsp;*/<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">,&nbsp;</span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Write&nbsp;a&nbsp;simple&nbsp;string&nbsp;to&nbsp;the&nbsp;file<br />&nbsp;*&nbsp;it&nbsp;will&nbsp;be&nbsp;ROT13&nbsp;transformed&nbsp;on&nbsp;the<br />&nbsp;*&nbsp;way&nbsp;out&nbsp;*/<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 /><br /></span><span style="color: #FF8000">/*&nbsp;Back&nbsp;up&nbsp;to&nbsp;the&nbsp;beginning&nbsp;of&nbsp;the&nbsp;file&nbsp;*/<br /></span><span style="color: #0000BB">rewind</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Read&nbsp;the&nbsp;contents&nbsp;of&nbsp;the&nbsp;file&nbsp;back&nbsp;out.<br />&nbsp;*&nbsp;Had&nbsp;the&nbsp;filter&nbsp;been&nbsp;applied&nbsp;to&nbsp;the<br />&nbsp;*&nbsp;read&nbsp;filter&nbsp;chain&nbsp;as&nbsp;well,&nbsp;we&nbsp;would&nbsp;see<br />&nbsp;*&nbsp;the&nbsp;text&nbsp;ROT13ed&nbsp;back&nbsp;to&nbsp;its&nbsp;original&nbsp;state&nbsp;*/<br /></span><span style="color: #0000BB">fpassthru</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Expected&nbsp;Output<br />&nbsp;&nbsp;&nbsp;---------------<br /><br />Guvf&nbsp;vf&nbsp;n&nbsp;grfg<br /><br />&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p>  <blockquote><p><b class="note">Note</b>:    <b>When using custom (user) filters</b><br />   <span class="simpara">    <a href="function.stream-filter-register.html" class="function">stream_filter_register()</a> must be called first    in order to register the desired user filter to <i><tt class="parameter">filtername</tt></i>.   </span>  </p></blockquote>  <blockquote><p><b class="note">Note</b>:    <span class="simpara">    Stream data is read from resources (both local and remote) in chunks,    with any unconsumed data kept in internal buffers.  When a new    filter is appended to a stream, data in the internal buffers is processed through    the new filter at that time.  This differs from the behavior of    <a href="function.stream-filter-prepend.html" class="function">stream_filter_prepend()</a>.   </span>  </p></blockquote>  <p class="simpara">   See also   <a href="function.stream-filter-register.html" class="function">stream_filter_register()</a>,   <a href="function.stream-filter-prepend.html" class="function">stream_filter_prepend()</a>, and   <a href="function.stream-get-filters.html" class="function">stream_get_filters()</a>.  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.stream-encoding.html">stream_encoding</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stream-filter-prepend.html">stream_filter_prepend</a></div> <div class="up"><a href="ref.stream.html">Stream Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

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