php code with + symbol issue

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
tycoon79
Forum Newbie
Posts: 4
Joined: Fri Jan 23, 2009 5:12 am

php code with + symbol issue

Post 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
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: php code with + symbol issue

Post by prometheuzz »

(answer removed)

Never mind, I see you cross posted this in more regex forums. I'm not wasting my time on you.
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: php code with + symbol issue

Post 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.
Post Reply