PHP: Fetching foldername from URL

Discussion in 'PHP' started by cancer10, Mar 15, 2008.

  1. #1
    Hi,

    I came up with this problem last night.

    I have a URL http://www.mysite.com

    How do I fetch the folder name that was supplied in the URL.

    For example:


    http://www.mysite.com/xyz
    or
    http://mysite.com/myfolder
    or
    http://www.mysite.com/xxx


    Please note that I can either use www or http://www or just http:// in my domain name but I need to fetch the folder name that was supplied in the URL.

    PS:

    I tried the following code, but it didnt revealed the foldername supplied

    <?php
    echo $_SERVER['HTTP_HOST'];
    ?>
     
    Code (markup):


    Please help.


    Thanx
     
    cancer10, Mar 15, 2008 IP
  2. mulari

    mulari Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You should look on the php function "parse_url"
    using "parse_url($url)" will return an array with the information you need.
    Array
    (
    [scheme] => http
    [host] => hostname
    [path] => /xyz
    )

    if you want the current viewed page dir you simply do:
    dirname($_SERVER['REQUEST_URI']);
     
    mulari, Mar 15, 2008 IP