PHP filter_list() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Filter

Definition

In PHP, filter_list() returns an array with the names of all filters that your PHP installation supports.

It is a quick way to see which filter names you can use. You can pair each name with filter_id() to find the matching number.

Syntax

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

PHP
$filters = filter_list();
CallWhat it does
filter_list()Returns an array of all supported filter names, such as int, boolean, and validate_email.
in_array('validate_email', filter_list())Checks whether a specific filter name is available.
array_slice(filter_list(), 0, 3)Gets just the first three filter names from the list.

filter_list() takes no arguments. The list contains filter names, not the FILTER_* constant names. Use filter_id() to turn a name from this list into the numeric ID.

Library declarations
PHP
filter_list(): array

Parameters

ParameterDescription
—This function takes no parameters.

Return Value

Return ValueDescription
arrayA list of filter names, for example int, boolean, float, validate_email, and unsafe_raw.

PHP Examples

Example 1 — Check That a Filter Exists

Get the list of filter names and check if the email validation filter is in it.

PHP
<?php
$filters = filter_list();

echo "Has validate_email: ", in_array('validate_email', $filters, true) ? "yes" : "no", PHP_EOL;
echo "Has int: ", in_array('int', $filters, true) ? "yes" : "no", PHP_EOL;

How It Works

  1. filter_list() returns an array of filter names.
  2. in_array() checks whether a name appears in that array.
  3. Both validate_email and int are standard filters, so both are found.
  4. The true argument makes the comparison strict.

Example 2 — Names Are Not Constant Names

The list holds short names like 'int', so searching for a constant name finds nothing.

PHP
<?php
$filters = filter_list();

echo "int: ", in_array('int', $filters, true) ? "found" : "not found", PHP_EOL;
echo "FILTER_VALIDATE_INT: ", in_array('FILTER_VALIDATE_INT', $filters, true) ? "found" : "not found", PHP_EOL;

How It Works

  1. The list stores names such as int and validate_email.
  2. Searching for 'int' succeeds.
  3. FILTER_VALIDATE_INT is a PHP constant, not a filter name, so it is not in the list.
  4. Use filter_id('int') if you need the number that the constant holds.

Example 3 — A Helper to Test Filter Support

Write a small function that tells you whether a filter name is available, then use filter_id() on every name in the list.

PHP
<?php
function supportsFilter(string $name): bool
{
    return in_array($name, filter_list(), true);
}

echo "validate_ip: ", supportsFilter('validate_ip') ? "yes" : "no", PHP_EOL;
echo "magic: ", supportsFilter('magic') ? "yes" : "no", PHP_EOL;

$allHaveIds = true;
foreach (filter_list() as $name) {
    if (filter_id($name) === false) {
        $allHaveIds = false;
    }
}
echo "Every name has an ID: ", $allHaveIds ? "yes" : "no", PHP_EOL;

How It Works

  1. supportsFilter() wraps in_array() so the check is easy to reuse.
  2. validate_ip is a real filter, so the result is yes. magic is made up, so it is no.
  3. The loop calls filter_id() for each name from filter_list().
  4. Every real filter name has an ID, so the final line prints yes.

Frequently Asked Questions

It returns an array of strings, where each string is the name of a filter supported by your PHP installation. For example, int, boolean, validate_email, and unsafe_raw.
Pass the name to filter_id(). For example, filter_id('validate_email') returns the same number as FILTER_VALIDATE_EMAIL.
No. You call it with empty parentheses and it always returns the full list of filter names.
No. The name for FILTER_VALIDATE_EMAIL is 'validate_email', and the name for FILTER_VALIDATE_INT is just 'int'. Constants are used in code, while names are used with filter_id().
No. The list can differ between PHP versions, since filters are added or deprecated over time. Search for the name you need instead.

Next: filter_var()

filter_var() checks or cleans a single value, such as an email address, a number, or a URL.

filter_var() 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