Extracting the directory info and filename from URL

Discussion in 'PHP' started by trevlar, Dec 11, 2006.

  1. #1
    I'm trying to find the absolutely most efficient way to get /folder/subfolder/filename.php?id=1000 from http://www.website.com/folder/subfolder/filename.php?id=1000

    It should also work if the "www" is not specified in the URL or if it's "https://".

    I searched and found this page: http://forums.digitalpoint.com/showthread.php?t=190219 , but it's doing just the exact opposite of what I'm trying to do.

    Thanks!
     
    trevlar, Dec 11, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    <? 
    $url = parse_url($url);
    echo $url['path'] . $url['query'];
    ?>
    
    PHP:
    ??
     
    krakjoe, Dec 11, 2006 IP
  3. sukantab

    sukantab Well-Known Member

    Messages:
    2,075
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    110
    #3
    
    <?
    echo $_SERVER['PHP_SELF']; 
    ?>
    
    PHP:
     
    sukantab, Dec 13, 2006 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    phpself would be filename.php
     
    krakjoe, Dec 17, 2006 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    
    
    <?php
    
    echo $_SERVER['REQUEST_URI']; 
    
    ?>
    
    PHP:
     
    nico_swd, Dec 17, 2006 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    yeah or that, I always forget about that one .....
     
    krakjoe, Dec 17, 2006 IP
  7. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <? echo $_SERVER['REQUEST_URI']; ?>

    is correct.......
     
    weknowtheworld, Dec 18, 2006 IP