Okay, I've just solved my own problem by simply doing:

settype($input,"integer");

but.. I'm puzzled about why the following more complicated solution didn't work. The ASCII value for 0 is 48, and for 9 is 57.

The idea was to read a character at a time from the $rawinput string, check if it's within the correct range, and if so concantenate it to the end of the output string.

However bizarrely this seems to behave incorrectly, as it cuts out "0" as well. Can anyone explain why it does this?

function stripnum($rawinput)
{

for($x=0;$x < strlen($rawinput);$x++)
{
$c = substr($rawinput,$x,1);

switch($c){

case ($c > chr(47) and $c < chr(58)):
$output .=$c;
break;

default:
echo "escaped character at ".$x;
break;
}

}

return $output;
}


I just can't find the bug in my code at all, and even though I found a better way to do it, it's annoying me that this didn't work!!!

Beth Gore
--
http://bethanoia.dyndns.org/
rss feed: http://bethanoia.dyndns.org/bethanoia.rss


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to