Easy Tutorial
❮ Php Removed Extensions Func Array Reduce ❯

PHP filter_input() Function



Definition and Usage

The filter_input() function retrieves input from outside the script (such as form input) and filters it.

This function is used to validate variables from insecure sources, such as user input.

The function can retrieve input from various sources:

If successful, it returns the filtered data. If it fails, it returns FALSE. If the "variable" parameter is not set, it returns NULL.

Syntax

Parameter Description
input_type Required. Specifies the input type. See the list above for possible types.
variable Required. Specifies the variable to filter.
filter Optional. Specifies the ID of the filter to use. The default is FILTER_SANITIZE_STRING. See the Complete PHP Filter Reference for filter IDs, which can be either the ID name (e.g., FILTER_VALIDATE_EMAIL) or the ID number (e.g., 274).
options Optional. Specifies an associative array containing flags/options or a single flag/option. Check each filter for possible flags and options.

Example

In this example, we use the filter_input() function to filter a POST variable. The received POST variable is a valid email address:

The output of the code is as follows:


❮ Php Removed Extensions Func Array Reduce ❯