note 29405 deleted from function.intval by sniper

From: Date: Sat, 23 Aug 2003 00:26:42 +0000
Subject: note 29405 deleted from function.intval by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54924@lists.php.net to get a copy of this message
Note Submitter: php(a)esurfers°com ---- 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; }

« previous php.notes (#54924) next »