Page 1 of 1
preg_match
Posted: Fri Sep 12, 2008 5:47 am
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?
Re: preg_match
Posted: Fri Sep 12, 2008 7:44 am
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!
Re: preg_match
Posted: Sat Sep 13, 2008 6:49 am
by swetha
Code: Select all
if (preg_match('arg1','arg2','arg3' ) || preg_match('arg1','arg2','arg3' ))
{
statements here
}
Re: preg_match
Posted: Sat Sep 13, 2008 8:30 am
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 ]]] )
Re: preg_match
Posted: Sun Sep 14, 2008 2:24 am
by swetha
thanks.i had used the correct preg_match..just as an example have used 'arg1','arg2' etc
Re: preg_match
Posted: Sun Sep 14, 2008 2:41 am
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
}