Home >Backend Development >PHP Problem >What is the usage of filter_input in php
In PHP, the "filter_input()" function is used to verify variables from non-safe sources, obtain input from outside the script, and filter it. If successful, the filtered data will be returned, and if it fails, false will be returned. , the syntax is "filter_input(input type, filtered variable, filter ID, array)".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
The filter_input() function gets input from outside the script and filters it.
This function is used to verify variables from non-safe sources, such as user input.
This function can get input from various sources:
INPUT_GET
INPUT_POST
INPUT_COOKIE
INPUT_ENV
INPUT_SERVER
filter_input(input_type, variable, filter, options)input_type Required. Specifies the input type. See the list of possible types above. variable specifies the variable to filter. filter is optional. Specifies the ID of the filter to use. The default is FILTER_SANITIZE_STRING. options Specifies an array containing flags/options. Check the possible flags and options for each filter. The example is as follows: In this example, we use the filter_input() function to filter a POST variable. Accepted POST variables are valid e-mail addresses.
<?php if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) { echo "E-Mail is not valid"; } else { echo "E-Mail is valid"; } ?>Output is similar: E-Mail is valid Recommended learning: "
PHP Video Tutorial"
The above is the detailed content of What is the usage of filter_input in php. For more information, please follow other related articles on the PHP Chinese website!