note 33727 deleted from function.is-int by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Oct 2010 04:49:26 +0000 |
| Subject: | note 33727 deleted from function.is-int by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173540@lists.php.net to get a copy of this message | ||
Note Submitter: phpguru at gmx dot ch
----
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.