preg_match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

preg_match

Post by swetha »

can we use the or operator with preg_match
eg

if preg_match('arg1','arg2','arg3' ) || preg_match('arg1','arg2','arg3' )

i get a unexpected T_BOOLEAN_OR error in that error.Is there any restriction in using
|| with preg_match?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: preg_match

Post by jaoudestudios »

Yes you can use a preg_match with an OR in the IF statement.

What is your code?

The example you gave is incorrect use of conditional statements!
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

Re: preg_match

Post by swetha »

Code: Select all

 
if (preg_match('arg1','arg2','arg3' ) || preg_match('arg1','arg2','arg3' ))
{
 statements here
}
 
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: preg_match

Post by jaoudestudios »

Your IF statement is correct but you preg_match is not.
eg

Code: Select all

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

Re: preg_match

Post by swetha »

thanks.i had used the correct preg_match..just as an example have used 'arg1','arg2' etc
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: preg_match

Post by jaoudestudios »

Oh ok.

Then use this in your IF statement be more specific dont use short hand - just in case thats causing an issue.

Code: Select all

 
if (preg_match('arg1','arg2','arg3' ) > 0 || preg_match('arg1','arg2','arg3' ) > 0)  // because preg_match returns a value not a boolean result
{
 statements here
}
 
Post Reply