PHP stream_get_filters() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Stream

Definition

In PHP, stream_get_filters() returns a list of the stream filter names currently registered and available in this PHP process.

The list includes built-in filters such as string.toupper and convert.base64-encode, plus any filters you registered with stream_filter_register(). Use it to discover what you can pass to stream_filter_append() or stream_filter_prepend().

Syntax

Call stream_get_filters() with the values you need. Start with this line.

PHP
$filters = stream_get_filters();
CallWhat it does
stream_get_filters()Returns an array of filter name strings.
in_array("string.rot13", stream_get_filters())Checks whether the rot13 filter is available.
count(stream_get_filters())Counts how many filters PHP currently knows.

The exact list depends on your PHP build and loaded extensions. Tutorial output below checks for well-known names so the printed lines stay stable across machines.

Library declarations
PHP
stream_get_filters(): array

Parameters

ParameterDescription
—This function takes no parameters.

Return Value

Return ValueDescription
arrayAn indexed array of filter name strings.

PHP Examples

Example 1 — Check for Common String Filters

Ask whether a few built-in string filters are present and print yes or no for each.

PHP
<?php
$filters = stream_get_filters();
$want = ["string.toupper", "string.tolower", "string.rot13"];

foreach ($want as $name) {
    echo $name, ": ", in_array($name, $filters, true) ? "yes" : "no", PHP_EOL;
}

How It Works

  1. stream_get_filters() returns every known filter name.
  2. We loop over three common built-in string filters.
  3. in_array() reports whether each name appears in the list.
  4. A normal PHP install includes these three, so each line prints yes.

Example 2 — Count Available Filters

Print how many filters are registered, using a fixed sample count for this tutorial.

PHP
<?php
$filters = stream_get_filters();
$count = count($filters);

echo "filter count >= 3: ", $count >= 3 ? "yes" : "no", PHP_EOL;
echo "has convert.base64-encode: ",
    in_array("convert.base64-encode", $filters, true) ? "yes" : "no", PHP_EOL;

How It Works

  1. count() measures the size of the filter list.
  2. Instead of printing a machine-specific number, we check that at least three filters exist.
  3. We also look for convert. base64-encode, a common convert.* filter.
  4. Both checks pass on a typical PHP build.

Example 3 — Use a Listed Filter on a Stream

Confirm string.toupper is listed, then append it and write a short word.

PHP
<?php
if (!in_array("string.toupper", stream_get_filters(), true)) {
    echo "missing", PHP_EOL;
    return;
}

$fp = fopen("php://memory", "r+");
stream_filter_append($fp, "string.toupper", STREAM_FILTER_WRITE);
fwrite($fp, "hi");
rewind($fp);
echo stream_get_contents($fp), PHP_EOL;
fclose($fp);

How It Works

  1. First we verify string. toupper is in the filter list.
  2. A memory stream is opened and the filter is attached for writes.
  3. fwrite("hi") is transformed to uppercase letters.
  4. Reading the stream back prints HI.

Frequently Asked Questions

It returns an array of stream filter names that are registered and available, including built-ins and user-registered filters.
No. It only lists names. Use stream_filter_append() or stream_filter_prepend() to attach a filter to a stream.
Loaded extensions and custom stream_filter_register() calls change the list. Check with in_array() for the names you need.
From stream_filter_register(), which links a filter name to a PHP class that implements the filter.
Common ones include string.toupper, string.tolower, string.rot13, convert.base64-encode, and convert.base64-decode.

Next: stream_get_line()

stream_get_line() reads one line (or one chunk) from a stream, stopping when it sees a cus.

stream_get_line() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful