PHP.nl

stream_filter_append

stream_filter_append

Attach a filter to a stream

resource **stream_filter_append** resource $stream string $filter_name int $mode mixed $params

Adds to the list of filters attached to .
filter_name``stream

streamThe target stream.

filter_nameThe filter name.

mode By default, will attach the filter to the if the file was opened for reading (i.e. File Mode: , and/or ). The filter will also be attached to the if the file was opened for writing (i.e. File Mode: , , and/or ). , , and/or can also be passed to the parameter to override this behavior. stream_filter_append``read filter chain``r``+``write filter chain``w``a``+``STREAM_FILTER_READ``STREAM_FILTER_WRITE``STREAM_FILTER_ALL``mode

params This filter will be added with the specified to the of the list and will therefore be called last during stream operations. To add a filter to the beginning of the list, use . paramsendstream_filter_prepend

Returns a resource on success or false on failure. The resource can be used to refer to this filter instance during a call to . stream_filter_remove

false is returned if is not a resource or if cannot be located. stream``filter_name

Voorbeeld: Controlling where filters are applied

<?php
/* Open a test file for reading and writing */
$fp = fopen('test.txt', 'w+');

/* Apply the ROT13 filter to the
 * write filter chain, but not the
 * read filter chain */
stream_filter_append($fp, "string.rot13", STREAM_FILTER_WRITE);

/* Write a simple string to the file
 * it will be ROT13 transformed on the
 * way out */
fwrite($fp, "This is a test\n");

/* Back up to the beginning of the file */
rewind($fp);

/* Read the contents of the file back out.
 * Had the filter been applied to the
 * read filter chain as well, we would see
 * the text ROT13ed back to its original state */
fpassthru($fp);

fclose($fp);

/* Expected Output
   ---------------

Guvf vf n grfg

 */
?>

Opmerking: > ### When using custom (user) filters

 must be called first
in order to register the desired user filter to .

stream_filter_register``filter_name

Opmerking: > 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 . stream_filter_prepend

Opmerking: > When a filter is added for read and write, two instances of the filter are created. must be called twice with and to get both filter resources. stream_filter_append``STREAM_FILTER_READ``STREAM_FILTER_WRITE

stream_filter_register``stream_filter_prepend``stream_get_filters