note 29405 added to function.intval
| From: | php at rack1 dot php dot net | Date: | Wed, 12 Feb 2003 17:12:47 +0000 |
| Subject: | note 29405 added to function.intval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43831@lists.php.net to get a copy of this message | ||
I don't think casting to (int) and back to (string) is correct:
Casting "03" to int will produce 3
Casting 3 to string will produce "3"
But "03" is not === "3".
You should remove leading zeroes and plus and final dot and as in "+00004.e1" that is a
legal int
Also strtoupper() is not correct, because it will assume that ";,.#" is a number.
Also things like if($var+1 != 1 || $var == "0") {...} will fail if $var is
"0000"
Maybe this will work (code is not tested):
function is_intValued($var) {
if(is_numeric($var)) {
// It's a number so it's at least a float
$var=(float)$var;
return ((float)(int)$var)===$var;
}
return false;
}
--
http://www.php.net/manual/en/function.intval.php
http://master.php.net/manage/user-notes.php?action=edit+29405
http://master.php.net/manage/user-notes.php?action=delete+29405
http://master.php.net/manage/user-notes.php?action=reject+29405