Hi,

Tuesday, December 3, 2002, 12:12:09 PM, you wrote:
BG> Okay, I've just solved my own problem by simply doing:

BG> settype($input,"integer");

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

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

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

BG> function stripnum($rawinput)
BG>         {

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

BG>                 switch($c){

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

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

BG>         }

BG>         return $output;
BG> }


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

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

switch will treat 0 as false which ever way you try to dress it up :)
I solved a similar problem like this:

switch($c){

           case (ord($c) > 47 && ord($c) < 58)?True:False:
                $output .=$c;
           break;

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

-- 
regards,
Tom


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

Reply via email to