Open In App

PHP | filter_id() Function

Last Updated : 29 Dec, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The filter_id() function is an inbuilt function in PHP which returns the filter ID of a specified filter name. It is used to get the filter id of the particular filter in PHP by using filter_id function by giving the name of the filter as input and get the associated id to it. Syntax:

int filter_id( $filtername )

Parameters: This function accepts single parameter $filtername which is mandatory. It holds the filter name. Return Value: It returns the ID of the filter on success or False if filter doesn't exist. Note: This function available for PHP 5.2.0 and newer versions. Example 1: 

php
<?php
// PHP program to get the filter ID

// Use filter_id function to return
// the filter id 
echo(filter_id("validate_email"));

?>
Output:
274

Explanation: validate_email is name of the filter here. The filter_id ("validate_email") returns 274 as ID of the filter validate_email. Example 2: This example shows all the available filter name and it's corresponding filter id represented in filter_list() function. 

php
<?php
// PHP program to display the filter
// list with ID

foreach (filter_list() as $id =>$filter) {
    echo '<tr><td>' . $filter . '</td><td>'
        . filter_id($filter) . '</td></tr>';
}

?>
Output:
int257
boolean258
float259
validate_regexp272
validate_domain277
validate_url273
validate_email274
validate_ip275
validate_mac276
string513
stripped513
encoded514
special_chars515
full_special_chars522
unsafe_raw516
email517
url518
number_int519
number_float520
magic_quotes521
callback1024

Explanation: The filter_list() function returning list of filter name. Using filter_id() function id of the filter name is extracted and given output as HTML table component (to represent in better way only). References: http://php.net/manual/en/function.filter-id.php


Next Article

Similar Reads