Re: Bug in Ereg?

From: Date: Fri, 15 Aug 2003 22:27:17 +0000
Subject: Re: Bug in Ereg?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-159768@lists.php.net to get a copy of this message
* Thus wrote Kris Yates (kris@2binteractive.com): > Hi, > > I have a form with checkboxes that POSTs to a PHP script. > > What is posted [ from phpinfo() ]: > > _POST["color-1"] on > _POST["color-4"] on > _POST["color-6"] on There is more post data than this. > > > Parser: > foreach($_POST as $ThisVar=>$ThisVal){ > if(ereg("color-", $ThisVar) AND $ThisVal=="on" OR $ThisVal==1){ > $newVarA=explode("-", $ThisVar); > $colors.="$newVarA[1]:"; > } > } Your logic, as jennifer pointed, isn't probably what your expecting. You're POST data has a value of 1 somewhere. Also, ereg is very expensive for doing exact string matches like you are doing there, best to use the str* functions avaible to do tasks like this. ie: if ('color-' == substr($ThisVar, 0, 6)) And then no need to explode into an array and then extract the value (more overhead).. since the format is known you can do something like: $colors .= substr($ThisVar, 6); HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#159768) next »