函数名称:stream_filter_prepend()
适用版本:PHP 4 >= 4.3.0, PHP 5, PHP 7
函数描述:stream_filter_prepend() 函数在指定流上添加一个过滤器
用法: stream_filter_prepend(resource $stream, string $filtername [, int $read_write = STREAM_FILTER_ALL [, mixed $params = NULL ]]): resource|false
参数:
- $stream:需要添加过滤器的流资源。
- $filtername:过滤器的名称。
- $read_write(可选):指定过滤器的读写类型。可选值为STREAM_FILTER_READ、STREAM_FILTER_WRITE或STREAM_FILTER_ALL,默认为STREAM_FILTER_ALL。
- $params(可选):传递给过滤器的参数。
返回值: 如果成功,stream_filter_prepend() 函数返回新的流资源,如果失败则返回 false。
示例: 假设我们有一个文件 "example.txt" 包含以下内容: Hello, World!
我们可以使用 stream_filter_prepend() 函数在读取文件内容之前添加一个过滤器,将文本全部转换为大写:
输出结果: HELLO, WORLD!