Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 6047

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Attach a filter to a stream</title>

 </head>
 <body><div class="manualnavbar" 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 description" id="refsect1-function.stream-filter-append-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>stream_filter_append</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stream</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$filtername</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$read_write</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$params</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Adds <em><code class="parameter">filtername</code></em> to the list of filters
   attached to <em><code class="parameter">stream</code></em>.  
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-filter-append-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">stream</code></em></span>
     <dd>

      <p class="para">
       The target stream.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">filtername</code></em></span>
     <dd>

      <p class="para">
       The filter name.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">read_write</code></em></span>
     <dd>

      <p class="para">
       By default,  <span class="function"><strong>stream_filter_append()</strong></span> will
       attach the filter to the <em>read filter chain</em>
       if the file was opened for reading (i.e. File Mode:
       <em>r</em>, and/or <em>+</em>).  The filter
       will also be attached to the <em>write filter chain</em>
       if the file was opened for writing (i.e. File Mode:
       <em>w</em>, <em>a</em>, and/or <em>+</em>).
       <strong><code>STREAM_FILTER_READ</code></strong>,
       <strong><code>STREAM_FILTER_WRITE</code></strong>, and/or
       <strong><code>STREAM_FILTER_ALL</code></strong> can also be passed to the
       <em><code class="parameter">read_write</code></em> parameter to override this behavior.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">params</code></em></span>
     <dd>

      <p class="para">
       This filter will be added with the specified 
       <em><code class="parameter">params</code></em> 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
        <span class="function"><a href="function.stream-filter-prepend.html" class="function">stream_filter_prepend()</a></span>.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-filter-append-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a resource which can be used to refer to this filter
   instance during a call to  <span class="function"><a href="function.stream-filter-remove.html" class="function">stream_filter_remove()</a></span>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stream-filter-append-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        Prior to PHP 5.1.0, this function returns <strong><code>TRUE</code></strong> on success
        or <strong><code>FALSE</code></strong> on failure.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-filter-append-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4016">
    <p><strong>Example #1 Controlling where filters are applied</strong></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>
 </div>


 <div class="refsect1 notes" id="refsect1-function.stream-filter-append-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>When using custom (user) filters</strong><br />
   <span class="simpara">
     <span class="function"><a href="function.stream-filter-register.html" class="function">stream_filter_register()</a></span> must be called first
    in order to register the desired user filter to <em><code class="parameter">filtername</code></em>.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <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
     <span class="function"><a href="function.stream-filter-prepend.html" class="function">stream_filter_prepend()</a></span>.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    When a filter is added for read and write, two instances of the filter
    are created.  <span class="function"><strong>stream_filter_append()</strong></span> must be called twice 
    with <strong><code>STREAM_FILTER_READ</code></strong> and 
    <strong><code>STREAM_FILTER_WRITE</code></strong> to get both filter resources.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stream-filter-append-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li class="member"> <span class="function"><a href="function.stream-filter-register.html" class="function" rel="rdfs-seeAlso">stream_filter_register()</a> - Register a user defined stream filter</span></li>
   <li class="member"> <span class="function"><a href="function.stream-filter-prepend.html" class="function" rel="rdfs-seeAlso">stream_filter_prepend()</a> - Attach a filter to a stream</span></li>
   <li class="member"> <span class="function"><a href="function.stream-get-filters.html" class="function" rel="rdfs-seeAlso">stream_get_filters()</a> - Retrieve list of registered filters</span></li>
  </ul>
 </div>

</div><hr /><div class="manualnavbar" 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>