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)
|
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