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 >= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">stream_filter_append</span> — <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"><?php<br /></span><span style="color: #FF8000">/* Open a test file for reading and writing */<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">'test.txt'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w+'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Apply the ROT13 filter to the<br /> * write filter chain, but not the<br /> * read filter chain */<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">, </span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Write a simple string to the file<br /> * it will be ROT13 transformed on the<br /> * way out */<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 /><br /></span><span style="color: #FF8000">/* Back up to the beginning of the file */<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">/* Read the contents of the file back out.<br /> * Had the filter been applied to the<br /> * read filter chain as well, we would see<br /> * the text ROT13ed back to its original state */<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">/* Expected Output<br /> ---------------<br /><br />Guvf vf n grfg<br /><br /> */<br /></span><span style="color: #0000BB">?></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(); ?>