Regex on URL to get subfolder

Discussion in 'PHP' started by Christian Little, Nov 7, 2008.

  1. #1
    Let's say I have the url www.example.com/ad1/

    I want to be able to pull out just "ad1" regardless of the rest of the URL.

    So if somebody goes to any of these pages:

    /ad1/index.html
    /ad1/results.html
    /ad1/testimonials.html

    I want to have a line of code that will extract just the "ad1" part of the URL, which will always be just the first subfolder.

    +green to whoever gives me the right coding :)
     
    Christian Little, Nov 7, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    php.net/pathinfo
    php.net/parse_url
     
    EricBruggema, Nov 8, 2008 IP