Home  >  Article  >  Backend Development  >  php filter_input filter function example tutorial_PHP tutorial

php filter_input filter function example tutorial_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:00:21983browse

Definition and usage
The filter_input() function gets the input to the filter from an external script and filters it.

This function is used to validate variable forms from unsafe sources, such as user input.

This feature can input several sources:

INPUT_GET
INPUT_POST
INPUT_COOKIE
INPUT_ENV
INPUT_SERVER
INPUT_SESSION (not implemented yet)
INPUT_REQUEST (not yet implemented)
Returns filtered data on success, false failure or NULL if the 'variable' parameter is not set.

Grammar

filter_input(input_type, variable, filter, options)

		Parameter
Description
input_type 必需的。指定输入类型。见可能类型上述清单
variable 必需的。指定变量过滤
filter 任择。指定编号的过滤器来使用。默认是FILTER_SANITIZE_STRING 。检查PHP的过滤器完全可能的参考过滤器过滤器编号可以是一个编号名称(如FILTER_VALIDATE_EMAIL )或身份证号码(如274 )
options 任择。指定一个关联数组的旗帜/选项或一个单一的旗帜/选项。检查每个过滤器的各种可能的选择和旗帜
Description
input_type Required. Specify the input type. See list of possible types above
variable Required. Specify variable filter
filter Optional. Specifies the numbered filter to use. The default is FILTER_SANITIZE_STRING. Checking PHP filters is entirely possible by referencing the filter. The filter number can be a number name (like FILTER_VALIDATE_EMAIL) or an id number (like 274)
options Optional. Specifies an associative array of flags/options or a single flag/option. Check the various possible choices and flags for each filter
看看实例.


For example, in this example we use the filter_input () function to filter the variables. The received variable is a valid e-mail address:

<!--?phpif (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) { echo "E-Mail is not valid"; }else { echo "E-Mail is valid"; }?-->
 
输出为.
 

E-Mail is valid

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445511.htmlTechArticleDefinition and Usage The filter_input() function gets the input filter from an external script and filters it. This function is used to validate variable forms from unsafe sources, such as user input. ...
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