note 116961 added to filter.filters.validate
| From: | maruerru at gmail dot com | Date: | Thu, 26 Mar 2015 23:09:03 +0000 |
| Subject: | note 116961 added to filter.filters.validate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202051@lists.php.net to get a copy of this message | ||
Often I see some code like the following:
$value = "12";
if( filter_var($value, FILTER_VALIDATE_INT) )
{
// validated as an int
}
The above works as intended, except when $value is "0". In the above case it will be
interpreted as FALSE.
For the correct behavior, you have not only to check if it is equal (==) to false, but also identic
(===) to FALSE:
$value = " 0 ";
if( filter_var($value, FILTER_VALIDATE_INT) === FALSE )
{
// validated as an int
}
I hope, I could help.
----
Server IP: 72.52.91.14
Probable Submitter: 84.187.77.92
----
Manual Page -- http://php.net/manual/en/filter.filters.validate.php
Edit -- https://master.php.net/note/edit/116961
Del: integrated -- https://master.php.net/note/delete/116961/integrated
Del: useless -- https://master.php.net/note/delete/116961/useless
Del: bad code -- https://master.php.net/note/delete/116961/bad+code
Del: spam -- https://master.php.net/note/delete/116961/spam
Del: non-english -- https://master.php.net/note/delete/116961/non-english
Del: in docs -- https://master.php.net/note/delete/116961/in+docs
Del: other reasons-- https://master.php.net/note/delete/116961
Reject -- https://master.php.net/note/reject/116961
Search -- https://master.php.net/manage/user-notes.php