Re: An integer?

From: Date: Mon, 21 Aug 2000 06:10:29 +0000
Subject: Re: An integer?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-12716@lists.php.net to get a copy of this message
> 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? you could try this: $int_var = (int)$your_form_variable; $int_var now has no choice but to be an integer. If you run: is_int($int_var) it should return TRUE; Do with it what you want. However, keep in mind that if you have non-number digits in $your_form_variable, then the type cast is not going to give you what you expect, but most likely a zero. -jeremy brand _______________________________________________________________________ GnuPG Fingerprint: 9F5E 95E0 1CC2 E054 84EA 6099 8ACD 9DBA D2C0 5EA9 _ http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more __

« previous php.general (#12716) next »