filter_input_array

(PHP 5 >= 5.2.0, PHP 7)

filter_input_array锟斤拷取一系锟斤拷锟解部锟斤拷锟斤拷锟斤拷锟斤拷锟揭匡拷锟斤拷通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷

说锟斤拷

filter_input_array ( int $type [, mixed $definition [, bool $add_empty = true ]] ) : mixed

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟揭拷锟饺★拷芏锟斤拷锟斤拷却锟斤拷锟斤拷锟截革拷锟斤拷锟斤拷filter_input()时锟斤拷锟斤拷锟矫★拷

锟斤拷锟斤拷

type

INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV之一锟斤拷

definition

一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷椤R伙拷锟斤拷锟叫э拷募锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�string锟斤拷一锟斤拷锟斤拷效锟斤拷值要么锟斤拷一锟斤拷filter type锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷array 指锟斤拷锟剿癸拷锟斤拷锟斤拷锟斤拷锟斤拷示锟斤拷选锟筋。锟斤拷锟街碉拷锟揭伙拷锟斤拷锟斤拷椋拷锟矫达拷锟斤拷锟斤拷锟叫э拷募锟斤拷锟斤拷锟斤拷锟� filter锟斤拷 锟斤拷锟斤拷指锟斤拷 filter type锟斤拷flags 锟斤拷锟斤拷指锟斤拷锟轿猴拷锟斤拷要锟斤拷锟节癸拷锟斤拷锟斤拷锟侥憋拷示锟斤拷锟斤拷锟斤拷 options 锟斤拷锟斤拷指锟斤拷锟轿猴拷锟斤拷要锟斤拷锟节癸拷锟斤拷锟斤拷锟斤拷选锟筋。 锟轿匡拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷玫锟斤拷锟斤拷锟斤拷锟剿碉拷锟斤拷锟�

锟斤拷锟斤拷锟斤拷锟揭诧拷锟斤拷锟斤拷锟揭伙拷锟�filter constant锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷么锟斤拷锟斤拷锟叫碉拷锟斤拷锟叫憋拷锟斤拷锟斤拷锟结被锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷恕锟�

add_empty

锟节凤拷锟斤拷值锟斤拷锟斤拷锟� NULL 锟斤拷为锟斤拷锟斤拷锟节的硷拷锟斤拷

锟斤拷锟斤拷值

锟斤拷锟斤拷晒锟斤拷幕锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟侥憋拷锟斤拷锟斤拷锟斤拷锟介,锟斤拷锟绞э拷艿幕锟斤拷锟斤拷锟� FALSE 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街碉拷锟斤拷锟斤拷锟斤拷锟斤拷失锟斤拷锟津返伙拷 FALSE 锟斤拷锟斤拷锟�variable_name 锟斤拷锟斤拷锟节的伙拷锟津返伙拷 NULL 锟斤拷 锟斤拷锟斤拷锟绞� FILTER_NULL_ON_FAILURE 锟斤拷使锟斤拷锟剿o拷锟斤拷么锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷 FALSE 锟斤拷锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 NULL 锟斤拷

锟斤拷锟斤拷

Example #1 一锟斤拷 filter_input_array() 锟斤拷锟斤拷锟斤拷

<?php
error_reporting
(E_ALL E_STRICT);
/* data actually came from POST
$_POST = array(
    'product_id'    => 'libgd<script>',
    'component'     => '10',
    'versions'      => '2.0.33',
    'testscalar'    => array('2', '23', '10', '12'),
    'testarray'     => '2',
);
*/

$args = array(
    
'product_id'   => FILTER_SANITIZE_ENCODED,
    
'component'    => array('filter'    => FILTER_VALIDATE_INT,
                            
'flags'     => FILTER_REQUIRE_ARRAY
                            
'options'   => array('min_range' => 1'max_range' => 10)
                           ),
    
'versions'     => FILTER_SANITIZE_ENCODED,
    
'doesnotexist' => FILTER_VALIDATE_INT,
    
'testscalar'   => array(
                            
'filter' => FILTER_VALIDATE_INT,
                            
'flags'  => FILTER_REQUIRE_SCALAR,
                           ),
    
'testarray'    => array(
                            
'filter' => FILTER_VALIDATE_INT,
                            
'flags'  => FILTER_REQUIRE_ARRAY,
                           )

);

$myinputs filter_input_array(INPUT_POST$args);

var_dump($myinputs);
echo 
"\n";
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

array(6) {
  ["product_id"]=>
  string(17) "libgd%3Cscript%3E"
  ["component"]=>
  array(1) {
    [0]=>
    int(10)
  }
  ["versions"]=>
  string(6) "2.0.33"
  ["doesnotexist"]=>
  NULL
  ["testscalar"]=>
  bool(false)
  ["testarray"]=>
  array(1) {
    [0]=>
    int(2)
  }
}

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
5.4.0 锟斤拷锟� add_empty 锟斤拷锟斤拷.

注锟斤拷

Note:

锟斤拷 INPUT_SERVER 锟斤拷锟斤拷锟叫诧拷没锟斤拷 REQUEST_TIME 锟斤拷锟斤拷为锟斤拷锟角憋拷锟皆猴拷锟斤拷氲�$_SERVER 锟叫的★拷

锟轿硷拷

  • filter_input() - 通锟斤拷锟斤拷锟狡伙拷取锟截讹拷锟斤拷锟解部锟斤拷锟斤拷锟斤拷锟斤拷锟揭匡拷锟斤拷通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
  • filter_var_array() - 锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷夜锟斤拷锟斤拷锟斤拷锟�
  • Types of filters