note 91003 deleted from function.filter-input-array by danbrown

From: Date: Wed, 20 May 2009 15:00:59 +0000
Subject: note 91003 deleted from function.filter-input-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155802@lists.php.net to get a copy of this message
Note Submitter: Stephen Dewey ---- 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) } }

« previous php.notes (#155802) next »