note 91003 added to function.filter-input-array

From: Date: Wed, 20 May 2009 14:51:28 +0000
Subject: note 91003 added to function.filter-input-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-155797@lists.php.net to get a copy of this message
The example given is actually not correct. 'component' and 'testarray' will return false because the inputs are not arrays. <?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, '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 ) ); $myinputs = filter_input_array(INPUT_POST, $args); var_dump($myinputs); echo "\n"; ?> The above example will output: array(6) { ["product_id"]=> array(1) { [0]=> string(17) "libgd%3Cscript%3E" } ["component"]=> array(1) { [0]=> int(10) } ["versions"]=> array(1) { [0]=> string(6) "2.0.33" } ["doesnotexist"]=> NULL ["testscalar"]=> bool(false) ["testarray"]=> array(1) { [0]=> int(2) } } ---- Server IP: 208.69.120.35 Probable Submitter: 65.46.73.222 ---- Manual Page -- http://www.php.net/manual/en/function.filter-input-array.php Edit -- https://master.php.net/note/edit/91003 Del: integrated -- https://master.php.net/note/delete/91003/integrated Del: useless -- https://master.php.net/note/delete/91003/useless Del: bad code -- https://master.php.net/note/delete/91003/bad+code Del: spam -- https://master.php.net/note/delete/91003/spam Del: non-english -- https://master.php.net/note/delete/91003/non-english Del: in docs -- https://master.php.net/note/delete/91003/in+docs Del: other reasons-- https://master.php.net/note/delete/91003 Reject -- https://master.php.net/note/reject/91003 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#155797) next »