Current Location: Home> Function Categories> stream_filter_prepend

stream_filter_prepend

Attach the filter to the stream
Name:stream_filter_prepend
Category:Stream
Programming Language:php
One-line Description:Add a filter to the specified 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:

  • $stream: The stream resource that needs to be added to the filter.
  • $filtername: The name of the filter.
  • $read_write (optional): Specifies the read and write type of the filter. The optional values ​​are STREAM_FILTER_READ, STREAM_FILTER_WRITE, or STREAM_FILTER_ALL, and the default is STREAM_FILTER_ALL.
  • $params (optional): Parameters passed to the filter.

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!

Similar Functions
Popular Articles