Open In App

PHP | filter_id() Function

Last Updated : 29 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
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:

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads