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

From: Date: Wed, 20 May 2009 15:00:43 +0000
Subject: note 91005 deleted from function.filter-input-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155801@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 but the flags FILTER_REQUIRE_ARRAY are used. Also, the results are not returned in nested arrays. Here's a corrected example: <?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); ?> The above example will output: array(6) { ["product_id"]=> string(17) "libgd%3Cscript%3E" ["component"]=> int(10) ["versions"]=> string(6) "2.0.33" ["doesnotexist"]=> NULL ["testscalar"]=> bool(false) ["testarray"]=> int(2) }

« previous php.notes (#155801) next »