filter_input
(PHP 5 >= 5.2.0, PHP 7)
filter_input — Gets a specific external variable by name and optionally filters it
Description
Parameters
-
type
-
One of
INPUT_GET
,INPUT_POST
,INPUT_COOKIE
,INPUT_SERVER
, orINPUT_ENV
. -
variable_name
-
Name of a variable to get.
-
filter
-
The ID of the filter to apply. The Types of filters manual page lists the available filters.
If omitted,
FILTER_DEFAULT
will be used, which is equivalent toFILTER_UNSAFE_RAW
. This will result in no filtering taking place by default. -
options
-
Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array.
Return Values
Value of the requested variable on success, FALSE
if the filter fails,
or NULL
if the variable_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
Example #1 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_var() - Filters a variable with a specified filter
- filter_input_array() - Gets external variables and optionally filters them
- filter_var_array() - Gets multiple variables and optionally filters them
- Types of filters
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-filter-input.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.