php fopen append,PHP stream_filter_append 用法 手册 | 示例代码

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值