Retrieves an external variable (e.g., from form input) and optionally applies a filter to it.
<?php if (!filter_input(INPUT_GET, “email”, FILTER_VALIDATE_EMAIL)) { echo(“Email is not valid”); } else { echo(“Email is valid”); } ?> |
The filter_input() function retrieves an external variable (e.g., from form input) and optionally applies a filter to it.
It is used to validate variables from insecure sources, such as user input.
filter_input(type, variable, filter, options) |
Parameter |
Description |
type |
Required. Specifies the input type to check for, which can be one of the following: · INPUT_GET · INPUT_POST · INPUT_COOKIE · INPUT_SERVER · INPUT_ENV |
variable |
Required. Specifies the name of the variable to retrieve. |
filter |
Optional. Specifies the ID or name of the filter to apply. The default is `FILTER_DEFAULT |
options |
Optional. Specifies one or more flags or options to apply. Refer to each filter’s documentation for available options and flags. |
Return Value: |
The variable’s value on success, FALSE on failure, or NULL if the variable is not set. |
PHP Version: |
5.2+ |