(PHP 5 >= 5.2.0, PHP 7)
filter_input — 通锟斤拷锟斤拷锟狡伙拷取锟截讹拷锟斤拷锟解部锟斤拷锟斤拷锟斤拷锟斤拷锟揭匡拷锟斤拷通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
type
INPUT_GET
, INPUT_POST
,
INPUT_COOKIE
, INPUT_SERVER
锟斤拷
INPUT_ENV
之一锟斤拷
variable_name
锟斤拷锟斤拷取锟侥憋拷锟斤拷锟斤拷锟斤拷
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 to
FILTER_UNSAFE_RAW
.
This will result in no filtering taking place by default.
options
一锟斤拷选锟斤拷墓锟斤拷锟斤拷锟斤拷椋拷锟斤拷甙锟轿伙拷锟斤拷值谋锟绞撅拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷选锟筋,锟斤拷锟斤拷通锟斤拷锟斤拷锟斤拷锟� "flags" 位去锟结供锟斤拷些锟斤拷示锟斤拷
锟斤拷锟斤拷晒锟斤拷幕锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟绞э拷锟斤拷蚍祷锟� FALSE
锟斤拷锟斤拷锟�variable_name
锟斤拷锟斤拷锟节的伙拷锟津返伙拷 NULL
锟斤拷
锟斤拷锟斤拷锟绞� FILTER_NULL_ON_FAILURE
锟斤拷使锟斤拷锟剿o拷锟斤拷么锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷 FALSE
锟斤拷锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 NULL
锟斤拷
Example #1 一锟斤拷 filter_input() 锟斤拷锟斤拷锟斤拷
<?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>";
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
You have searched for Me & son. <a href='?search=Me%20%26%20son'>Search again.</a>