Stream Filters

最后更新于:2022-04-02 02:32:02

[TOC] ## 接口 ``` stream_filter_prepend 将过滤器附加到流 stream_filter_append 将过滤器附加到流 stream_filter_remove 移除过滤器 stream_get_filters 获取已注册的数据流过滤器列表 stream_filter_register 注册过滤器 ``` ## 实例 ### 新增一个过滤器 ``` class str_test extends php_user_filter { public function filter($in, $out, &$consumed, $closing) { while($bucket = stream_bucket_make_writeable($in)){ $bucket->data = strtoupper($bucket->data); $consumed += $bucket->datalen; stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } $fp = fopen("php://output","wb"); stream_filter_register("str_test","str_test"); stream_filter_append($fp,"str_test"); fwrite($fp,"abc"); // ABC ``` ### 获取注册的过滤器 ``` print_r(stream_get_filters()); //Array //( // [0] => convert.iconv.* // [1] => mcrypt.* // [2] => mdecrypt.* // [3] => string.rot13 // [4] => string.toupper // [5] => string.tolower // [6] => string.strip_tags // [7] => convert.* // [8] => consumed // [9] => dechunk // [10] => zlib.* // [11] => str_test //) // ```
';