Re: integer checking problem from query string

From: Date: Sat, 28 Apr 2001 22:33:04 +0000
Subject: Re: integer checking problem from query string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-50773@lists.php.net to get a copy of this message
It's a string, not an integer. Try using is_numeric() instead. To see what type it is, do this : echo gettype($phonenumber); // prints string You may want to strip all non-numbers first, just in case they enter : 333-333-3333 Something like : $phonenumber = preg_replace('/[^0-9]/','',$phonenumber); Btw, $string = '3'; // is a string. $number = 3; // is an integer regards, philip On Sat, 28 Apr 2001, Jamie Saunders wrote: > > Hi, > > I'm submitting a phone number from an HTML form to a PHP page that examines > it to see if it's an integer: > > form.html: > > <html> > <form method="get" action="validate.php"> > <input type="text" name="phonenumber"> > <input type="submit"> > </form> > > validate.php: > > <html> > <?php > > $phonenumber = trim($phonenumber); > > if (is_int($phonenumber)) { > echo "Integer"; > } else { > echo "Not Integer"; > } > > ?> > > </html> > > > However, for some reason the script doesn't recognize the number as an > Integer - why is this and how can I remedy it? > > > Jamie Saunders > Mail: webprogramming@jamie-s.co.uk > Web: http://jamie-s.co.uk > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#50773) next »