er I was joking, The code I suggested would be a bit long winded to do what is already there. Lets just count it as a moment of madness.
The only down side to using any of the ctype functions is the version of php being used. 4.2.0 has them enabled by default earlier versions don't ( please correct me if Im wrong here ) so the ctype functions may not be available.
on a side note how about this for numeric checking not my code its from the user comments in the manual
$val = -123.45E293;
$match = '^-?\d+(?:\.\d+)?(?:[Ee]-?\d+)$';
if (preg_match('|' . $match . '|', $val)){
echo $val . ' is a number!';
} else {
echo $val . ' is not a number!';
}
or how about
<?
// there is a function called "is_numeric" in PHP, so i call this one
// "is_it_number"
// one probably does not have to initialize the variables like i do, but
// i'm used to PL/SQL requirements so ...
// this function will allow the tested string to include only
// digits and only one . (dot) or , (comma). neither of both
// can be a trailing character of the string.
// please note that we do not check here if the string is an empty string
//
function is_it_number($str_in) {
$c1 = 0;
$c2 = 0;
for ($i = 0; $i < strlen($str_in); $i++)
{
if (preg_match("/[0-9]|[.,]/", substr($str_in,$i,1))) {
;;
}
else {
$c1++;
}
if (preg_match("/[.,]/", substr($str_in,$i,1))) {
$c2++;
}
}
if ($c1 > 0 or $c2 > 1 or preg_match("/[.,]$|[ ]+/", $str_in)) {
return (boolean) FALSE;
}
else {
return (boolean) TRUE;
}
}
?>
Again long winded ways to use is_numeric
Mark.
p.s. what a long and pointless post 🙂