php8.5
Home/ Manual/ filter / functions/ filter_input

filter_input

PHP function Edit on GitHub ✎

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

Gets a specific external variable by name and optionally filters it

Description

filter_input(int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed

Parameters

type

One of the INPUT_* constants.

Warning

The 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_name

Name of a variable to filter inside the corresponding type superglobal.

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
<?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:

output
You have searched for Me &#38; son.
<a href='?search=Me%20%26%20son'>Search again.</a>

See Also

Source: reference/filter/functions/filter-input.xml · from the official PHP manual (php/doc-en)