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:
<?php
$fp = fopen("test.txt", "r");
stream_filter_prepend($fp, "string.rot13",
STREAM_FILTER_READ);
$contents=fread($fp,1024);
echo $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:
<?php
$fp = fopen("test.txt", "w+");
stream_filter_append($fp, "string.rot13",
STREAM_FILTER_WRITE);
fwrite($fp, "This is a test\n"); first written, then ROT13 tranformed and lastly
written to 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