Getting relative URL out of an absolute one

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mike809
    New Member
    • Aug 2011
    • 5

    Getting relative URL out of an absolute one

    I'd like to parse the URL part after TLD. In another words I'm interested in the bold part http://bytes.com/submit/304/ of this URL.
    Let's assume that all the URLs are valid and formally flawless.
    It seems to me one way is to make a regular expression like this: "anything, dot, 2 to 4 letters, slash, anything". The Regexp might look like this:
    Code:
    $regexp = '@.+\.[a-z]{2,4}\/(.+)@si';
    Is my thinking correct or am I overlooking something?
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    This has already been done for you...



    Code:
    echo $_SERVER['REQUEST_URI'];
    Cheers,

    Dan
    Last edited by dlite922; Aug 22 '11, 03:33 PM. Reason: codetags

    Comment

    • mike809
      New Member
      • Aug 2011
      • 5

      #3
      Doesn't it work with the current URL only, that means the one which the script is called from? I need it to be done with strings stored in an array.

      Comment

      Working...