note 86775 added to function.filter-var
| From: | dyer85 at gmail dot com | Date: | Mon, 03 Nov 2008 10:00:00 +0000 |
| Subject: | note 86775 added to function.filter-var | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146078@lists.php.net to get a copy of this message | ||
Note that when using FILTER_VALIDATE_INT along with the FILTER_FLAG_ALLOW_HEX flag, the string
"2f", for example, is not validated successfully, because you must use the "0x"
prefix, otherwise, it treats the data as base 10.
The range options are also smart enough to recognize when the boundaries are exceeded in different
bases.
Here's an example:
<?php
$foo = '256';
$bar = '0x100';
var_dump(validate_int($foo)); // false, too large
var_dump(validate_int($bar)); // false, too large
function validate_int($input)
{
return filter_var(
$input,
FILTER_VALIDATE_INT,
// We must pass an associative array
// to include the range check options.
array(
'flags' => FILTER_FLAG_ALLOW_HEX,
'options' => array('min_range' => 1, 'max_range' =>
0xff)
)
);
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 96.240.47.235
----
Manual Page -- http://www.php.net/manual/en/function.filter-var.php
Edit -- https://master.php.net/note/edit/86775
Del: integrated -- https://master.php.net/note/delete/86775/integrated
Del: useless -- https://master.php.net/note/delete/86775/useless
Del: bad code -- https://master.php.net/note/delete/86775/bad+code
Del: spam -- https://master.php.net/note/delete/86775/spam
Del: non-english -- https://master.php.net/note/delete/86775/non-english
Del: in docs -- https://master.php.net/note/delete/86775/in+docs
Del: other reasons-- https://master.php.net/note/delete/86775
Reject -- https://master.php.net/note/reject/86775
Search -- https://master.php.net/manage/user-notes.php