note 37717 added to function.is-numeric

From: Date: Mon, 24 Nov 2003 08:05:11 +0000
Subject: note 37717 added to function.is-numeric
Groups: php.notes 
Request: Send a blank email to php-notes+get-60901@lists.php.net to get a copy of this message
Note that this function is not appropriate to check if "is_numeric" for very long strings. In fact, everything passed to this function is converted to long and then to a double. Anything greater than approximately 1.8e308 is too large for a double, so it becomes infinity, i.e. FALSE. What that means is that, for each string with more than 308 characters, is_numeric() will return FALSE, even if all chars are digits. However, this behaviour is platform-specific. http://www.php.net/manual/en/language.types.float.php In such a case, it is suitable to use regular expressions: function is_numeric_big($s=0) { return preg_match('/^-?\d+$/', $s); } ---- Manual Page -- http://www.php.net/manual/en/function.is-numeric.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37717 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37717&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37717&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60901) next »