note 116924 added to filter.filters.validate
| From: | bryanwayb at gmail dot com | Date: | Sun, 22 Mar 2015 04:18:06 +0000 |
| Subject: | note 116924 added to filter.filters.validate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202005@lists.php.net to get a copy of this message | ||
It's good to remember that using filter_var is primarily for filtering input values when doing
boolean logic comparisons. Take the following:
$value = "12";
if(filter_var($value, FILTER_VALIDATE_INT))
{
// validated as an int
}
The above works as intended, except when $value = "0". In which case filter_var returns a
0, aka false when used as a boolean.
For the correct behavior, do a zero check.
$value = " 0 ";
$filtered = filter_var($value, FILTER_VALIDATE_INT);
if($filtered || $filtered === 0)
{
// validated as an int
}
----
Server IP: 72.52.91.14
Probable Submitter: 71.252.128.180
----
Manual Page -- http://php.net/manual/en/filter.filters.validate.php
Edit -- https://master.php.net/note/edit/116924
Del: integrated -- https://master.php.net/note/delete/116924/integrated
Del: useless -- https://master.php.net/note/delete/116924/useless
Del: bad code -- https://master.php.net/note/delete/116924/bad+code
Del: spam -- https://master.php.net/note/delete/116924/spam
Del: non-english -- https://master.php.net/note/delete/116924/non-english
Del: in docs -- https://master.php.net/note/delete/116924/in+docs
Del: other reasons-- https://master.php.net/note/delete/116924
Reject -- https://master.php.net/note/reject/116924
Search -- https://master.php.net/manage/user-notes.php