note 91322 deleted from function.is-integer by danbrown
| From: | danbrown@php.net | Date: | Fri, 05 Jun 2009 16:56:53 +0000 |
| Subject: | note 91322 deleted from function.is-integer by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156402@lists.php.net to get a copy of this message | ||
Note Submitter: reinel dot arias at gmail dot com
Reason: bad code
----
PHP lacks of a function to know if a given string is or not a numeric one:
function isdigit($c) {
if ( $c>'0' && $c<'9' ) return(true);
else return (false);
}
function isnumeric($s) {
$numeric=true;
for ($i=0;$i<strlen($s);$i++) {
$ch=substr($s,$i,1);
if (!isdigit($ch)) {
$numeric=false;
break;
}
}
return($numeric);
}
$s="123xx567";
if (isnumeric($s)) {
print ("is numeric");
} else print ("is not numeric");