Re: An integer?
| From: | Lars Torben Wilson | Date: | Mon, 21 Aug 2000 06:23:48 +0000 |
| Subject: | Re: An integer? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-12719@lists.php.net to get a copy of this message | ||
Shaun writes:
>
> This may be a silly question, but I can't spot and easy way to do it, I
> want to check if the value inside a vriable is an integer. If I do
> is_int($variable) I always get false, because this variable qwas read in
> from a form so its a string, if I make the variable an integer using
> settype() I just end up with 0 if it was invalid, the number otherwise. I
> need something that will actually tell me if there the conversion was
> successfull. Am I missing something?
>
> Thanks,
> Shaun
Try this:
function is_int_str($str) {
return ((string)(int)$str) == $str;
}
If you also want to include float values as valid, just use
is_numeric(). But you said int...:)
Cheers,
Torben
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+