Hi ,
The function below returns a string "0" if ur string is not a valid
number .
It also works for decimal numbers.
Hope this is what you were looking for
regds
<?
function snum($data)
{
$str = trim($data);
$length = strlen($str);
$isdot = false;
$flag = true ;
if ($length == 0) $flag = false;
for ($i = 0 ; $i < $length && $flag ; $i++ )
{
if ( ( substr($str,$i,1) <= "9" && substr($str,$i,1) >= "0" ) || ( substr($str,$i,1) == "." && !$isdot ) )
{
if ( substr($str,$i,1) == "." ) $isdot = true;
}
else
{
$flag = false;
};
};
if ($flag)
{
return($str);
}
else
{
return("0");
};
};
?>