filter_input

(PHP 5 >= 5.2.0, PHP 7)

filter_input通锟斤拷锟斤拷锟狡伙拷取锟截讹拷锟斤拷锟解部锟斤拷锟斤拷锟斤拷锟斤拷锟揭匡拷锟斤拷通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷

说锟斤拷

filter_input ( int $type , string $variable_name [, int $filter = FILTER_DEFAULT [, mixed $options ]] ) : mixed

锟斤拷锟斤拷

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 &#38; son.
<a href='?search=Me%20%26%20son'>Search again.</a>

锟轿硷拷

  • filter_var() - 使锟斤拷锟截讹拷锟侥癸拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷
  • filter_input_array() - 锟斤拷取一系锟斤拷锟解部锟斤拷锟斤拷锟斤拷锟斤拷锟揭匡拷锟斤拷通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
  • filter_var_array() - 锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷夜锟斤拷锟斤拷锟斤拷锟�
  • Types of filters