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(): arrayIt 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 name | Equivalent constant |
|---|---|
int | FILTER_VALIDATE_INT |
validate_email | FILTER_VALIDATE_EMAIL |
validate_url | FILTER_VALIDATE_URL |
string | FILTER_SANITIZE_STRING (deprecated in PHP 8.1) |
full_special_chars | FILTER_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 => 1024Notice 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 byfilter_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.
Related functions
filter_id()— get the numeric ID for a filter name.filter_var()— apply a filter to a single value.filter_input()— filter a value from an external source (GET, POST, etc.).filter_var_array()— filter several values at once.
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.