W3docs

filter_list()

PHP provides a range of built-in functions for filtering and validating user input data. One such function is filter_list(), which is used to return a list of

Introduction

filter_list() is a PHP function that returns the names of all filters supported by your PHP build. PHP's filter extension is the engine behind validation and sanitization functions like filter_var() and filter_input(). Each filter — for emails, integers, URLs, IP addresses, and so on — has a short name and a numeric ID, and filter_list() lets you discover which ones are actually available at runtime.

This page covers the function's signature, what it returns, how it differs from the named FILTER_* constants, and the practical scenarios where listing the filters is useful (for example, building diagnostics or checking feature availability before relying on a filter).

Syntax

filter_list(): array

It takes no arguments and returns an indexed array of strings — the short name of every filter your PHP installation supports. The order is not guaranteed and may differ between PHP versions, so never depend on a specific position.

Return value

The array values are filter names (like "validate_email" or "int"), and the array keys are just sequential integers (0, 1, 2…). The keys are not filter IDs — a common misconception. To get the real numeric ID of a filter, pass its name to filter_id():

<?php

$filters = filter_list();
echo $filters[0] . "\n";            // e.g. "int"
echo filter_id($filters[0]) . "\n"; // e.g. 257  (FILTER_VALIDATE_INT)

These short names are the runtime equivalent of the FILTER_* constants you normally use:

Filter nameEquivalent constant
intFILTER_VALIDATE_INT
validate_emailFILTER_VALIDATE_EMAIL
validate_urlFILTER_VALIDATE_URL
stringFILTER_SANITIZE_STRING (deprecated in PHP 8.1)
full_special_charsFILTER_SANITIZE_FULL_SPECIAL_CHARS

Listing all available filters

The most common use is to enumerate every filter, often alongside its numeric ID for a quick reference:

<?php

foreach (filter_list() as $name) {
    echo $name . " => " . filter_id($name) . "\n";
}

Output (the exact set depends on your PHP version):

int => 257
boolean => 258
float => 259
validate_regexp => 272
validate_domain => 277
validate_url => 273
validate_email => 274
validate_ip => 275
validate_mac => 276
string => 513
stripped => 513
encoded => 514
special_chars => 515
full_special_chars => 522
unsafe_raw => 516
email => 517
url => 518
number_int => 519
number_float => 520
add_slashes => 523
callback => 1024

Notice that string and stripped share the ID 513 — they are two names for the same filter.

When would I use it?

You rarely call filter_list() in everyday validation code — for that you use filter_var() with a FILTER_* constant. filter_list() shines for:

  • Diagnostics and tooling. Printing the supported filters in a debug page or an environment-info dump.
  • Feature detection. Confirming a filter exists before you rely on it, especially for build-dependent or version-specific filters.
  • Building dynamic UIs. Populating a dropdown that lets an admin pick which filter to apply.

Checking whether a specific filter exists

Because the values are plain strings, you can test for a filter with in_array():

<?php

if (in_array("validate_email", filter_list(), true)) {
    echo "Email validation is available.\n";
} else {
    echo "Email filter is missing.\n";
}

Output:

Email validation is available.

Common gotchas

  • Keys are indexes, not IDs. Use filter_id() to translate a name into the ID accepted by filter_var().
  • Names vs. constants. filter_list() returns short names ("int"), not the constant names (FILTER_VALIDATE_INT). Don't compare the two directly.
  • Order is unstable. Always look up by name, never by position.

Conclusion

filter_list() returns the names of every filter your PHP build supports. It is mainly a discovery and diagnostic tool: pair it with filter_id() to inspect IDs, use in_array() to check availability, and reach for filter_var() when you actually need to validate or sanitize data.

Practice

Practice
Which of the following are valid filter names returned by filter_list() in PHP?
Which of the following are valid filter names returned by filter_list() in PHP?
Was this page helpful?