Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to use 2 patterns for preg_match

    Hey guys, this is pretty easy but don't know how to do it.

    Here's my code:
    PHP 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?
    PHP Code:
    $pattern '/site1/'
    Or do I just go:
    PHP Code:
    $pattern '/site1/';
    $pattern '/site2/'
    Thanks guys, hopefully one of you will be able to help.

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Well since I am kind of in a hurry to get this working, I decided to use just this:

    PHP Code:
    $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.

  • #3
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    maybe something like this

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

  • Users who have thanked funnymoney for this post:

    Love* (09-21-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •