显示下拉菜单

Test of filter_input_array() 本页面仅提供英文版本。

Example #1 : test success
Example #2 : test success
Example #3 : test success
Example #4 : test failed
Example #1
$input = [
  
'predefined_var' => '$_POST',
  
'data' => [
    
'product_id' => 'libgd<script>',
    
'component' => '10',
    
'versions' => '2.0.33',
    
'testscalar' => [
      
=> '2',
      
=> '23',
      
=> '10',
      
=> '12',
    ],
    
'testarray' => '2',
  ],
  
=> 'INPUT_POST',
  
=> [
    
'product_id' => 'FILTER_SANITIZE_ENCODED',
    
'component' => [
      
'filter' => 'FILTER_VALIDATE_INT',
      
'flags' => 'FILTER_REQUIRE_ARRAY',
      
'options' => [
        
'min_range' => 1,
        
'max_range' => 10,
      ],
    ],
    
'versions' => 'FILTER_SANITIZE_ENCODED',
    
'doesnotexist' => 'FILTER_VALIDATE_INT',
    
'testscalar' => [
      
'filter' => 'FILTER_VALIDATE_INT',
      
'flags' => 'FILTER_REQUIRE_SCALAR',
    ],
    
'testarray' => [
      
'filter' => 'FILTER_VALIDATE_INT',
      
'flags' => 'FILTER_REQUIRE_ARRAY',
    ],
  ],
]
$expected_output = $test_output
$test_output = [
  
'result' => [
    
'mixed' => [
      
'product_id' => 'libgd%3Cscript%3E',
      
'component' => false,
      
'versions' => '2.0.33',
      
'doesnotexist' => NULL,
      
'testscalar' => false,
      
'testarray' => false,
    ],
  ],
  
'php_version' => '7.1.33 Linux x86_64',
]
Example #2
$input = [
  
'predefined_var' => '$_GET',
  
'data' => [
    
'product_id' => 'libgd<script>',
    
'component' => '10',
    
'versions' => '2.0.33',
    
'testscalar' => [
      
=> '2',
      
=> '23',
      
=> '10',
      
=> '12',
    ],
    
'testarray' => '2',
  ],
  
=> 'INPUT_POST',
  
=> [
    
'product_id' => 'FILTER_SANITIZE_ENCODED',
  ],
]
$expected_output = $test_output
$test_output = [
  
'result' => [
    
'mixed' => [
      
'product_id' => NULL,
    ],
  ],
  
'php_version' => '7.1.33 Linux x86_64',
]
Example #3
$input = [
  
'predefined_var' => 123,
  
'data' => [
    
'product_id' => 'libgd<script>',
    
'component' => '10',
    
'versions' => '2.0.33',
    
'testscalar' => [
      
=> '2',
      
=> '23',
      
=> '10',
      
=> '12',
    ],
    
'testarray' => '2',
  ],
  
=> 'INPUT_POST',
  
=> [
    
'product_id' => 'FILTER_SANITIZE_ENCODED',
  ],
]
$expected_output = $test_output
$test_output = [
  
'errors' => [
    
=> [
      
'code' => 256,
      
'message' => 'this variable name is invalid (123)',
    ],
  ],
  
'php_version' => '7.1.33 Linux x86_64',
]
Example #4
$input = [
  
'predefined_var' => '$_GET',
  
'data' => [
    
'width' => 2,
    
'length' => 3,
    
'height' => 4,
    
'weight' => 5,
  ],
  
=> 'INPUT_GET',
  
=> [
    
'width' => [
      
'filter' => 'FILTER_CALLBACK',
      
'options' => 'double',
    ],
    
'length' => [
      
'filter' => 'FILTER_CALLBACK',
      
'options' => '$cube',
    ],
    
'height' => [
      
'filter' => 'FILTER_CALLBACK',
      
'options' => 'pbx_callbacks::double',
    ],
    
'weight' => [
      
'filter' => 'FILTER_CALLBACK',
      
'options' => [
        
=> '$object',
        
=> 'cube',
      ],
    ],
  ],
]
$expected_output = [
  
'result' => [
    
'mixed' => [
      
'width' => 4,
      
'length' => 27,
      
'height' => 8,
      
'weight' => 125,
    ],
  ],
  
'php_version' => '5.6.8 WINNT i586',
]
$test_output = [
  
'result' => [
    
'mixed' => [
      
'width' => '2',
      
'length' => '3',
      
'height' => '4',
      
'weight' => '5',
    ],
  ],
  
'php_version' => '7.1.33 Linux x86_64',
]