RE: [PHP] Bug in Ereg?

From: Date: Fri, 15 Aug 2003 22:13:14 +0000
Subject: RE: [PHP] Bug in Ereg?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-159767@lists.php.net to get a copy of this message
> What is posted [ from phpinfo() ]: > > _POST["color-1"] on > _POST["color-4"] on > _POST["color-6"] on > > > Parser: > foreach($_POST as $ThisVar=>$ThisVal){ > if(ereg("color-", $ThisVar) AND $ThisVal=="on" OR $ThisVal==1){ > $newVarA=explode("-", $ThisVar); > $colors.="$newVarA[1]:"; > } > } > > Expected Output: > > $colors="1:4:6:"; > > Real Output: > > $colors=":1:4:6:"; Do you have anything else in _POST that's equal to 1? I didn't look up order of operation, so I may be off here, but your if condition might not be doing what you are expecting. Try using parentheses to group it like this if(ereg("color-", $ThisVar) AND ($ThisVal=="on" OR $ThisVal==1)){ (I'm guessing that's what you want). Why are you using ereg anyway? You're not using a regular expression so strstr would work just as well and be slightly faster.

« previous php.general (#159767) next »