<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >stream_filter_append</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Stream Functions" HREF="ref.stream.html"><LINK REL="PREVIOUS" TITLE="stream_copy_to_stream" HREF="function.stream-copy-to-stream.html"><LINK REL="NEXT" TITLE="stream_filter_prepend" HREF="function.stream-filter-prepend.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.stream-copy-to-stream.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.stream-filter-prepend.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.stream-filter-append" ></A >stream_filter_append</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN111202" ></A ><P > (PHP 4 >= 4.3.0, PHP 5)</P >stream_filter_append -- Attach a filter to a stream.</DIV ><DIV CLASS="refsect1" ><A NAME="AEN111205" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >stream_filter_append</B > ( resource stream, string filtername [, int read_write [, mixed params]])<BR ></BR ><P > Adds <VAR CLASS="parameter" >filtername</VAR > to the list of filters attached to <VAR CLASS="parameter" >stream</VAR >. This filter will be added with the specified <VAR CLASS="parameter" >params</VAR > to the <SPAN CLASS="emphasis" ><I CLASS="emphasis" >end</I ></SPAN > 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" ><B CLASS="function" >stream_filter_prepend()</B ></A >. </P ><P > By default, <B CLASS="function" >stream_filter_append()</B > will attach the filter to the <VAR CLASS="literal" >read filter chain</VAR > if the file was opened for reading (i.e. File Mode: <VAR CLASS="literal" >r</VAR >, and/or <VAR CLASS="literal" >+</VAR >). The filter will also be attached to the <VAR CLASS="literal" >write filter chain</VAR > if the file was opened for writing (i.e. File Mode: <VAR CLASS="literal" >w</VAR >, <VAR CLASS="literal" >a</VAR >, and/or <VAR CLASS="literal" >+</VAR >). <TT CLASS="constant" ><B >STREAM_FILTER_READ</B ></TT >, <TT CLASS="constant" ><B >STREAM_FILTER_WRITE</B ></TT >, and/or <TT CLASS="constant" ><B >STREAM_FILTER_ALL</B ></TT > can also be passed to the <VAR CLASS="parameter" >read_write</VAR > parameter to override this behavior. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN111242" ></A ><P ><B >Exemplu 1. Controlling where filters are applied</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Open a test file for reading and writing */<br /></font><font color="#0000BB">$fp </font><font color="#007700">= </font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#DD0000">"test.txt"</font><font color="#007700">, </font><font color="#DD0000">"rw"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Apply the ROT13 filter to the<br /> * write filter chain, but not the<br /> * read filter chain */<br /></font><font color="#0000BB">stream_filter_append</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#DD0000">"string.rot13"</font><font color="#007700">, </font><font color="#0000BB">STREAM_FILTER_WRITE</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Write a simple string to the file<br /> * it will be ROT13 transformed on the<br /> * way out */<br /></font><font color="#0000BB">fwrite</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#DD0000">"This is a test\n"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Back up to the beginning of the file */<br /></font><font color="#0000BB">rewind</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br /><br /></font><font 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 /></font><font color="#0000BB">fpassthru</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br /><br /></font><font color="#0000BB">fclose</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Expected Output<br /> ---------------<br /><br />Guvf vf n grfg<br /><br /> */<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >When using custom (user) filters: </B > <A HREF="function.stream-filter-register.html" ><B CLASS="function" >stream_filter_register()</B ></A > must be called first in order to register the desired user filter to <VAR CLASS="parameter" >filtername</VAR >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > 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" ><B CLASS="function" >stream_filter_prepend()</B ></A >. </P ></BLOCKQUOTE ></DIV ><P > See also <A HREF="function.stream-filter-register.html" ><B CLASS="function" >stream_filter_register()</B ></A >, and <A HREF="function.stream-filter-prepend.html" ><B CLASS="function" >stream_filter_prepend()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.stream-copy-to-stream.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.stream-filter-prepend.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >stream_copy_to_stream</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.stream.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >stream_filter_prepend</TD ></TR ></TABLE ></DIV ></BODY ></HTML >