note 33727 added to function.is-int

From: Date: Sat, 05 Jul 2003 13:50:17 +0000
Subject: note 33727 added to function.is-int
Groups: php.notes 
Request: Send a blank email to php-notes+get-51551@lists.php.net to get a copy of this message
To Logan: There's also a simple non-regexp way to convert a (form) value into an integer if it consists of numbers only - although with a trap (see below): if ($_POST["number"] == (int)$_POST["number"]) $_POST["number"] = (int)$_POST["number"]; The "traps" (or "side effects") appear with values like "" (empty string) and false (boolean), which are converted to 0 (integer). But in certain cases this might be desirable or/and usefull ;-) Solutions like if (($_POST["number"] + 1 - 1) == $_POST["number"]) ... falls into the same category. ---- Manual Page -- http://www.php.net/manual/en/function.is-int.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33727 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33727&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33727&report=yes

« previous php.notes (#51551) next »