Validating get and post data

From: Date: Tue, 03 Dec 2002 02:12:09 +0000
Subject: Validating get and post data
Groups: php.general 
Request: Send a blank email to php-general+get-126795@lists.php.net to get a copy of this message
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

« previous php.general (#126795) next »