Current Location: Home> Function Categories> stream_filter_append

stream_filter_append

Attach the filter to the stream
Name:stream_filter_append
Category:Stream
Programming Language:php
One-line Description:Attach a filter to the specified stream

Function name: stream_filter_append()

Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7

Function description: Attach a filter to the specified stream

Syntax: bool stream_filter_append ( resource $stream , string $filtername [, int $read_write [, mixed $params ]] )

parameter:

  • $stream: The stream resource to add filter
  • $filtername: The name of the filter to be attached. The filter can be a built-in php filter or a user-defined filter
  • $read_write (optional): Specifies whether the filter operates in read mode or write mode. The default is STREAM_FILTER_ALL, indicating that it is suitable for read and write operations at the same time.
  • $params (optional): Extra parameters passed to the filter, which can be a single value or an array

Return value: Return true when successful, false when failure

Example:

 <?php // 创建一个文件流$stream = fopen('data.txt', 'r'); // 附加一个过滤器到流上if (stream_filter_append($stream, 'convert.base64-encode')) { // 读取并输出流的内容while (!feof($stream)) { echo fread($stream, 4096); } // 关闭流fclose($stream); } else { echo "无法附加过滤器到流上"; } ?>

In the above example, we first create a file stream using the fopen() function, and then attach the convert.base64-encode filter to the stream using the stream_filter_append() function. Next, we use the fread() function to read the contents of the stream and use echo output. Finally, we use the fclose() function to close the stream.

Note that convert.base64-encode is a built-in filter that converts data in a stream to Base64 encoding. Of course, you can also use other filters or custom filters to implement different functions.

Similar Functions
Popular Articles