downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.stream-filter-append.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.stream.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.stream-filter-append.php',
   
1 => 'stream_filter_append',
  ),
 
'up' =>
  array (
   
0 => 'ref.stream.php',
   
1 => 'Stream Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.stream-encoding.php',
   
1 => 'stream_encoding',
  ),
 
'next' =>
  array (
   
0 => 'function.stream-filter-prepend.php',
   
1 => 'stream_filter_prepend',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<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>
 <a name="function.stream-filter-append.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><b>stream_filter_append</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.php#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>

  </p>
 </div>


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

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">stream</tt></i>
</span>

     </dt><dd class="listitem">

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

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">filtername</tt></i>
</span>

     </dt><dd class="listitem">

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

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">read_write</tt></i>
</span>

     </dt><dd class="listitem">

      <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 class="constant">STREAM_FILTER_READ</tt></b>,
       <b><tt class="constant">STREAM_FILTER_WRITE</tt></b>, and/or
       <b><tt class="constant">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>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">params</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       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.php" class="function">stream_filter_prepend()</a>.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.stream-filter-append.returnvalues"></a><div class="refsect1 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 <a href="function.stream-filter-remove.php" class="function">stream_filter_remove()</a>.
  </p>
 </div>


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

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">5.1.0</td>
       <td align="left">
        Prior to PHP 5.1.0, this function returns <b><tt class="constant">TRUE</tt></b> on success
        or <b><tt class="constant">FALSE</tt></b> on failure.
       </td>
      </tr>

     </tbody>
   
   </table>
<p>
  </p>
 </div>


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


 <a name="function.stream-filter-append.notes"></a><div class="refsect1 notes">
  <h3 class="title">Notes</h3>
  <blockquote><p><b class="note">Note</b>:
   <b>When using custom (user) filters</b><br />
   <span class="simpara">
    <a href="function.stream-filter-register.php" 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.php" class="function">stream_filter_prepend()</a>.
   </span>
  </p></blockquote>
  <blockquote><p><b class="note">Note</b>:
   <span class="simpara">
    When a filter is added for read and write, two instances of the filter
    are created. <b>stream_filter_append()</b> must be called twice
    with <b><tt class="constant">STREAM_FILTER_READ</tt></b> and
    <b><tt class="constant">STREAM_FILTER_WRITE</tt></b> to get both filter resources.
   </span>
  </p></blockquote>
 </div>


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

</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites