Re: How to find if a string is an integer?
| From: | Felipe Desiderati | Date: | Thu, 12 Jun 2003 00:51:06 +0000 |
| Subject: | Re: How to find if a string is an integer? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-151173@lists.php.net to get a copy of this message | ||
try this:
if (ereg("^[0-9]+$", $_POST["var_int"))
echo "is int";
[]´s Felipe
----- Original Message -----
From: "Jean-Christian IMbeault" <jc@mega-bucks.co.jp>
To: <php-general@lists.php.net>
Sent: Wednesday, June 11, 2003 9:44 PM
Subject: [PHP] How to find if a string is an integer?
> 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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>