How to find if a string is an integer?
| From: | Jean-Christian IMbeault | Date: | Thu, 12 Jun 2003 00:44:40 +0000 |
| Subject: | How to find if a string is an integer? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-151172@lists.php.net to get a copy of this message | ||
I would like to test wether a $_POST var is an integer or not. What is the best way?
I ahve tried is_int() but that fails b/c $_POST vars are always strings. is_numeric() doesn't help because it doesn't differentiate bewteen numbers (1.0) and integers (1).
The best I have been able to come up with is:
if (is_numeric($var) && is_int((int)$var))
But I ma hoping there is something simpler ...
Any ideas?
thansk,
Jean-Christian Imbeault