PHP | filter_id() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to get the filter ID
  
// Use filter_id function to return
// the filter id 
echo(filter_id("validate_email"));
  
?>

chevron_right


Output:

274

Explanation: validate_email is name of the filter here. The flter_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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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>';
}
  
?>

chevron_right


Output:

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
magic_quotes 521
callback 1024

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



My Personal Notes arrow_drop_up

I am unrecognized crazy being with random thoughts

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.