note 95468 added to function.is-int
| From: | dtp at rodanmedia dot net | Date: | Mon, 04 Jan 2010 18:30:06 +0000 |
| Subject: | note 95468 added to function.is-int | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164632@lists.php.net to get a copy of this message | ||
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 ...
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 ...
if (is_numeric($search)) {echo "Say something nice.";
}else{
echo "Oops! You're no mathematician!";}
Just a noob's 'aha moment'.
----
Server IP: 192.41.40.227
Probable Submitter: 98.203.121.127
----
Manual Page -- http://www.php.net/manual/en/function.is-int.php
Edit -- https://master.php.net/note/edit/95468
Del: integrated -- https://master.php.net/note/delete/95468/integrated
Del: useless -- https://master.php.net/note/delete/95468/useless
Del: bad code -- https://master.php.net/note/delete/95468/bad+code
Del: spam -- https://master.php.net/note/delete/95468/spam
Del: non-english -- https://master.php.net/note/delete/95468/non-english
Del: in docs -- https://master.php.net/note/delete/95468/in+docs
Del: other reasons-- https://master.php.net/note/delete/95468
Reject -- https://master.php.net/note/reject/95468
Search -- https://master.php.net/manage/user-notes.php