Re: How to find if a string is an integer?
| From: | Brent Baisley | Date: | Thu, 12 Jun 2003 20:54:00 +0000 |
| Subject: | Re: How to find if a string is an integer? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-151306@lists.php.net to get a copy of this message | ||
Hmmm, didn't think about that. Here's something simple that seems to work in a couple of tests.
if(strlen($testValue-0) == strlen($testValue)) {
echo "Is a number";
} else {
echo "Is not a number";
}
Or, in one line:
(strlen($testValue-0) == strlen($testValue) ? 1 : 0)
Kind of a kludge, but it seems to work for positive, negative and decimals.
On Thursday, June 12, 2003, at 04:13 PM, Alex Earl wrote:
Jumping in a little late here, but what about is_numeric()? Haven't tried it, but the php manual for is_int says: Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric().The problem with is_numeric() is that something like "4e4" comes up as true, because it could be construed as a HEX value. Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577