PHP | filter_input() Function Last Updated : 29 Dec, 2022 Comments Improve Suggest changes Like Article Like Report The filter_input() is an inbuilt function in PHP which is used to get the specific external variable by name and filter it. This function is used to validate variables from insecure sources, such as user input from form. This function is very much useful to prevent some potential security threat like SQL Injection. Syntax: filter_input( $type, $variable_name, $filter, $options) Parameters: This function accepts four parameters as mentioned above and described below: $type: It is mandatory parameter and used to check the type of input. The list of filters are:INPUT_GETINPUT_POSTINPUT_COOKIEINPUT_SERVERINPUT_ENV$variable_name: It is required parameter. It is used to hold the name of variable which is to be checked.$filter: It is an optional parameter. It holds the name or ID of the filter. If this parameter is not set then FILTER_DEFAULT is used.$options: It is an optional parameter and used to specify one or more flags/options to use. It check for possible options and flags in each filter. If filter options are accepted then flags can be provided in "flags" field of array. Return Value: It returns the value of the variable on success or False on failure. If parameter is not set then return NULL. If the flag FILTER_NULL_ON_FAILURE is used, it returns FALSE if the variable is not set and NULL if the filter fails. Example 1: php <?php // PHP program to validate email using filter if (isset($_GET["email"])) { if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL) === false) { echo("Valid Email"); } else { echo("Invalid Email"); } } ?> Output: Valid Email Example 2: php <?php // Input type:INPUT_GET input name:search // filter name:FILTER_SANITIZE_SPECIAL_CHARS $search_variable_data = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_SPECIAL_CHARS); // Input type:INPUT_GET input name:search // filter name:FILTER_SANITIZE_ENCODED $search_url_data = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_ENCODED); echo "Search for $search_variable_data.\n"; echo "<a href='?search=$search_url_data'>Search again.</a>"; ?> Output: Search for tic tac & toc. Search again. References: http://php.net/manual/en/function.filter-input.php Comment More infoAdvertise with us Next Article PHP | filter_input() Function G gekcho Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | filter_list() Function The filter_list() function is an inbuilt function in PHP which is used to returns the list of all supported filters. Syntax: array filter_list( void ) Parameters: This function does not accepts any parameters. Return Values: It returns an array containing all names of supported filters. If it return 2 min read PHP | filter_id() Function 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( 2 min read PHP | Imagick filter() Function The Imagick::filter() function is an inbuilt function in PHP which is used to apply custom convolution kernel to the image. A kernel, convolution matrix, or mask is a small matrix. It is used for blur, sharpen, embossing, edge detection, and many more. Syntax: bool Imagick::filter( $ImagickKernel, $ 1 min read PHP | preg_filter() Function The preg_filter() function is an inbuilt function in PHP which is used to perform a regular expression search and replace the text. Syntax: preg_filter( $pattern, $replacement, $subject, $limit, $count ) Parameters: This function accepts five parameters as mention above and describe below. $pattern: 2 min read PHP | filter_has_var() function The filter_has_var() function is an inbuilt function in PHP which is used to check whether the variable available or not especially it checks if a variable of a specified input type exist or not. It returns True on success or False on failure. Syntax: bool filter_has_var( $type, $variable_name ) Par 2 min read PHP array_filter() Function This built-in function in PHP is used to filter the elements of an array using a user-defined function which is also called a callback function. The array_filter() function iterates over each value in the array, passing them to the user-defined function or the callback function. If the callback func 2 min read PHP | DsMap filter() Function The Ds\Map::filter() function is an inbuilt function in PHP which is used to create a new map using the filter function. Syntax: public Ds\Map::filter( $callback ) Parameters: It contains a single parameter $callback which is an optional parameter and it returns True if the value should be included, 2 min read PHP | DsSet filter() Function The Ds\Set::filter() function is an inbuilt function in PHP which is used to create new set using filter function. Syntax: Ds\Set public Ds\Set::filter( $callback ) Parameters: This function accepts single parameter $callback which is optional and it returns True if the value should be included, Fal 1 min read PHP | stream_get_filters() Function The stream_get_filters() function is an inbuilt function in PHP which is used to get the list of registered stream filters. Syntax: array stream_get_filters( void ) Parameters: This function does not accept any parameter. Return Value: This function returns an array containing the name of all availa 1 min read PHP in_array() Function The in_array() function in PHP is a built-in function that is used to check if a specific value exists within an array and returns a boolean result. Returns true if the value is found and false if the value is not found.Syntax:bool in_array(mixed $needle, array $haystack, bool $strict = false)In thi 3 min read Like