filter_list() function in PHP

The filter_list() function in PHP returns an array of all available filter names that can be used with PHP's filter functions like filter_var() and filter_input().

Syntax

filter_list()

Parameters

This function does not accept any parameters.

Return Value

The function returns an indexed array containing the names of all available filters. If no filters are available, it returns an empty array.

Example

Here's how to use filter_list() to display all available filters −

<?php
    $filters = filter_list();
    
    echo "Available filters:<br>";
    foreach ($filters as $filter) {
        echo "- " . $filter . "<br>";
    }
    
    echo "\nTotal filters available: " . count($filters);
?>

Practical Example with Filter IDs

You can combine filter_list() with filter_id() to get both filter names and their corresponding IDs −

<?php
    echo "Filter Name\t\tFilter ID<br>";
    echo str_repeat("-", 30) . "<br>";
    
    foreach (filter_list() as $filter) {
        $id = filter_id($filter);
        echo str_pad($filter, 20) . "\t" . $id . "<br>";
    }
?>

Common Use Cases

The filter_list() function is typically used for −

  • Debugging filter availability on different PHP installations
  • Building dynamic filter selection interfaces
  • Checking if specific filters are available before using them

Conclusion

The filter_list() function provides a simple way to discover all available PHP filters. It's particularly useful for debugging and building applications that need to work with various filter types dynamically.

Updated on: 2026-03-15T07:32:41+05:30

505 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements