Home >Backend Development >PHP Tutorial >How to get filter ID using filter_id() function in PHP? (code example)

How to get filter ID using filter_id() function in PHP? (code example)

青灯夜游
青灯夜游Original
2019-04-10 11:17:082308browse

The filter_id() function is a built-in function in PHP, which can return the filter ID number of the specified filter name. The following article will introduce to you how to use the filter_id() function in PHP to obtain the specified filter ID number. I hope it will be helpful to you.

How to get filter ID using filter_id() function in PHP? (code example)

PHP filter_id() function

The filter_id() function can return the filter with the specified filter name Device ID number. It is used to get the filter ID of a specific filter in PHP by using the filter_id function by taking the name of the filter as input and getting the ID associated with it.

Basic syntax

filter_id( $filtername )

Parameters: This filter_id() function accepts a single parameter $filtername, which is required; it contains the filter name .

Note: This function is available for PHP 5.2.0 and higher.

Code Example

The following is a code example to see how to use the filter_id() function to obtain the specified filter ID number.

Example 1:

<?php 
  
// 使用filter_id函数返回过滤器id
echo(filter_id("validate_email")); 
  
?>

Output:

274

Explanation: validate_email is the name of the filter here. flter_id("validate_email") returns 274 as the ID of the filter validate_email.

Example 2: Shows all available filter names and their corresponding filter IDs as represented in the filter_list() function.

<?php 
// 显示带有ID的过滤器列表
echo "<table border=&#39;1&#39; style=&#39;width:400px;border-collapse:collapse;&#39;>";
foreach (filter_list() as $id =>$filter) { 
    echo "<tr><td>" . $filter . "</td><td>"
        . filter_id($filter) . "</td>"; 
} 
echo "</table>";
?>

Output:

How to get filter ID using filter_id() function in PHP? (code example)

Description: The filter_list() function returns a list of filter names. Use the filter_id() function to extract the id of the filter name and output it as an HTML table component (just represented in a better way).

Recommended video tutorials: "PHP Tutorial"

The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to get filter ID using filter_id() function in PHP? (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn