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?
preg_match
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: preg_match
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!
What is your code?
The example you gave is incorrect use of conditional statements!
Re: preg_match
Code: Select all
if (preg_match('arg1','arg2','arg3' ) || preg_match('arg1','arg2','arg3' ))
{
statements here
}
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: preg_match
Your IF statement is correct but you preg_match is not.
eg
eg
Code: Select all
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )Re: preg_match
thanks.i had used the correct preg_match..just as an example have used 'arg1','arg2' etc
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: preg_match
Oh ok.
Then use this in your IF statement be more specific dont use short hand - just in case thats causing an issue.
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
}