Page 1 of 1

php code with + symbol issue

Posted: Fri Jan 23, 2009 6:01 am
by tycoon79
hi all..i need some help with php code

i've have this code

Code: Select all

 
$ValResult=0;
preg_match_all('/^[a-zA-Z- .,]{2,200}$/', $Valstring, $matches);
    foreach($matches[0] as $value){
        if($value!='' || $value!='0' || $value!='null'){
            $ValResult=1;
         }  
         else{
            $ValResult=0;
         }          
    }
     return $ValResult; 
 
and try it with

1)$Valstring='hulu'; and its return $ValResult=1--ok
2)$Valstring='hulu-'; and its return $ValResult=1--ok
3)$Valstring='hulu123'; and its return $ValResult=0--ok
4)$Valstring='hulu]'; and its return $ValResult=0--ok

but the when i try it with

5)$Valstring='hulu+'; and its return $ValResult=1--not ok

it suppose to return $ValResult=0

can someone help me with..thanking you all in advance for reviewing my post

Re: php code with + symbol issue

Posted: Fri Jan 23, 2009 6:11 am
by prometheuzz
(answer removed)

Never mind, I see you cross posted this in more regex forums. I'm not wasting my time on you.

Re: php code with + symbol issue

Posted: Fri Jan 23, 2009 6:28 am
by mintedjo
I think you are doing something crazy somewhere.
Its just bad code. If the string doesn't match then the loop doesnt execute so $ValResult will be whatever you told it to be before you start the loop.
Having said that I have no idea why it is returning 1 because looking at your code there you dont set it to 1 before the loop.