Hello firends
The difference betweem adding a stream filter first or last in the filte list in only the order they will be applied to streams.
For example, if you're reading data from a file, and a given filter is placed in first place with stream_filter_prepend()the data will be processed by that filter first.
This example reads out file data and the filter is applied at the beginning of the reading operation:
* read filter chain, but not the
* write filter chain */stream_filter_prepend($fp,"string.rot13",STREAM_FILTER_READ);// read file data$contents=fread($fp,1024);// file data is first filtered and stored in $contentsecho$contents;fclose($fp);?>
On the other hand, if stream_filter_append() is used, then the filter will be applied at the end of the data operation. The thing about this is only the order filters are applied to streams. Back to the example, it's not the same thing removing new lines from file data and then counting the number of characters, than performing the inverse process. In this case, the order that filters are applied to stream is important.
This example writes a test string to a file. The filter is applied at the end of the writing operation:
* 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 at the end of the
stream operation
* way out */fwrite($fp,"This is a testn");// string data isfirst written,then ROT13 tranformedandlastly
written to file/* Back up to the beginning of the file */rewind($fp);$contents=fread($fp,512);fclose($fp);
echo$contents;?>
In the first case, data is transformed at the end of the writing operation, while in the second one, data is first filtered and then stored in $contents.
With Regards
Hossein