note 95468 deleted from function.is-int by danbrown

From: Date: Thu, 28 Oct 2010 04:51:26 +0000
Subject: note 95468 deleted from function.is-int by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173542@lists.php.net to get a copy of this message
Note Submitter: dtp at rodanmedia dot net ---- An interesting thing I discovered is that is_int() may not work if checking a string for only numeric values. As a for instance, I have a form that requests user input, and the field name is $search. When the user clicks the "submit" button, the form then runs through a couple of verifications, including one that checks whether they entered only numbers in the search (this is for those who specify searching by only a receipt number), not a hex code or some other alpha-numeric term. When running ... <?php if (is_int($search)) {echo "Say something nice."; }else{ echo "Oops! You're no mathematician!";} ?> ... the script did not work. It read all entries, whether purely numeric or alpha-numeric, as non-integers. In this case, "is_numeric" is precisely what is needed to verify whether the search is only a number. So the script becomes ... <?php if (is_numeric($search)) {echo "Say something nice."; }else{ echo "Oops! You're no mathematician!";} ?> Just a noob's 'aha moment'.

« previous php.notes (#173542) next »