note 91005 added to function.filter-input-array
| From: | StephenDewey at osu1 dot php dot net | Date: | Wed, 20 May 2009 14:59:00 +0000 |
| Subject: | note 91005 added to function.filter-input-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-155799@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 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)
}
----
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/91005
Del: integrated -- https://master.php.net/note/delete/91005/integrated
Del: useless -- https://master.php.net/note/delete/91005/useless
Del: bad code -- https://master.php.net/note/delete/91005/bad+code
Del: spam -- https://master.php.net/note/delete/91005/spam
Del: non-english -- https://master.php.net/note/delete/91005/non-english
Del: in docs -- https://master.php.net/note/delete/91005/in+docs
Del: other reasons-- https://master.php.net/note/delete/91005
Reject -- https://master.php.net/note/reject/91005
Search -- https://master.php.net/manage/user-notes.php