Wildcard for REQUEST_URI

Discussion in 'PHP' started by mark_s, Apr 29, 2009.

  1. #1
    Is it possible to have a wildcard for a REQUEST_URI statement?

    For example I want every page that inside the "/test/" directory to show a particular banner. I've put a * in the code below to show where I need the wildcard placed:

    <? if($_SERVER['REQUEST_URI'] == "/test/*") echo '<a href="/"><img src="test-banner.jpg" border="0"/></a>';
    
    else echo '<a href="/"><img src="/assets/banner.jpg" /></a>'; ?>
    Code (markup):
     
    mark_s, Apr 29, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if (preg_match('`^/test/`', $_SERVER['REQUEST_URI']))
    ...
    Code (markup):
     
    SmallPotatoes, Apr 29, 2009 IP
  3. Estevan

    Estevan Peon

    Messages:
    120
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    0
    #3
    hello

     
    
    if(eregi("test/", $_SERVER['REQUEST_URI'])){ echo '<a href="/"><img src="test-banner.jpg" border="0"/></a>';}else{ echo '<a href="/"><img src="/assets/banner.jpg" /></a>'; }?>
    
    
    PHP:
    Best
     
    Estevan, Apr 29, 2009 IP
  4. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks guys! :)
     
    mark_s, Apr 29, 2009 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Not best; ereg functions have been deprecated and may no longer be available in future versions of PHP. Also, your regex will match on "main_stuff/test/whatever" which is not what was desired.
     
    SmallPotatoes, Apr 30, 2009 IP