View Full Version : How to use 2 patterns for preg_match

09-15-2009, 05:01 AM
Hey guys, this is pretty easy but don't know how to do it. :)

Here's my code:

$referer = $_SERVER['HTTP_REFERER'];
$pattern = '/site1/';
if (preg_match($pattern, $referer))

& What I want to do is to add another site under $pattern, & have the preg_match check if any of the 2 sites match the referering URL..

So basically, how do I add it here?

$pattern = '/site1/';

Or do I just go:

$pattern = '/site1/';
$pattern = '/site2/';

Thanks guys, hopefully one of you will be able to help. :)

09-15-2009, 05:42 AM
Well since I am kind of in a hurry to get this working, I decided to use just this:

$referer = $_SERVER['HTTP_REFERER'];
$pattern = '/site1/';
$pattern2 = '/site2/';
if (preg_match($pattern, $referer)) { echo 'Hey there'; }
elseif (preg_match($pattern2, $referer)) { echo 'Hey there'; }

But I am sure there must be a better way to do this? If so, feel free to post & educate me. :)

09-15-2009, 11:49 PM
maybe something like this

$referer = $_SERVER['HTTP_REFERER'];
$patterns = array('/site1/','/site2/');
if (preg_match($patterns, $referer)) { echo 'Hey there'; }