stream_filter_prepend
Attach the filter to the stream
Function name: stream_filter_prepend()
Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7
Function description: stream_filter_prepend() function adds a filter to the specified stream
Usage: stream_filter_prepend(resource $stream, string $filtername [, int $read_write = STREAM_FILTER_ALL [, mixed $params = NULL ]]): resource|false
parameter:
Return value: If successful, the stream_filter_prepend() function returns a new stream resource, and if failed, it returns false.
Example: Suppose we have a file "example.txt" that contains the following: Hello, World!
We can use the stream_filter_prepend() function to add a filter before reading the file contents and convert all text to capitalization:
<?php // 打开文件 $handle = fopen('example.txt', 'r'); // 添加过滤器 stream_filter_prepend($handle, 'string.toupper'); // 读取和输出文件内容 while (!feof($handle)) { echo fgets($handle); } // 关闭文件 fclose($handle); ?-->Output result: HELLO, WORLD!