filter_input
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
Gets a specific external variable by name and optionally filters it
Description
Parameters
typeOne of the
INPUT_*constants.WarningThe content of the superglobal that is being filtered is the original "raw" content provided by the SAPI, prior to any user modification to the superglobal. To filter a modified superglobal use
filter_var()instead.var_nameName of a variable to filter inside the corresponding
typesuperglobal.
Return Values
Value of the requested variable on success, false if the filter fails, or null if the var_name variable is not set. If the flag FILTER_NULL_ON_FAILURE is used, it returns false if the variable is not set and null if the filter fails.
Examples
A filter_input() example
<?php
$search_html = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_SPECIAL_CHARS);
$search_url = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_ENCODED);
echo "You have searched for $search_html.\n";
echo "<a href='?search=$search_url'>Search again.</a>";
?>The above example will output something similar to:
You have searched for Me & son.
<a href='?search=Me%20%26%20son'>Search again.</a>See Also
filter_input_array()filter_var()filter_var_array()- Validation filters
FILTER_VALIDATE_* - Sanitization filters
FILTER_SANITIZE_*