PHP Function Reference

PHP stream_filter_remove() Function



The PHP stream_filter_remove() function removes a stream filter previously added to a stream with stream_filter_prepend() or stream_filter_append(). Any data remaining in the filter's internal buffer will be flushed through to the next filter before removing it.

Syntax

stream_filter_remove(stream_filter)

Parameters

stream_filter Required. Specify the stream filter to be removed.

Return Value

Returns true on success or false on failure.

Example: dynamically re-filtering a stream

The example below shows the usage of stream_filter_remove() function.

<?php
//open a test file for writing
$fp = fopen("test.txt", "w");

//attaching 'string.rot13' filter to the file stream 
$rot13_filter = stream_filter_append($fp, "string.rot13", 
                                     STREAM_FILTER_WRITE);

//writing some content with filter attached                                
fwrite($fp, "This is ");

//removing the $rot13_filter filter
stream_filter_remove($rot13_filter);

//writing some content after removing filter
fwrite($fp, "a test\n");

//setting the file pointer to the start
rewind($fp);

//closing the file
fclose($fp);

//reading and displaying the content of the file
echo file_get_contents("test.txt");
?>

The output of the above code will be:

Guvf vf a test

❮ PHP Streams Reference