Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    how to parse a URL

    I'm looking for the solution to this problem:

    I want to be able to check on which page (or parent) i am by looking at the current url via php.

    My urls look like this:

    http://www.adomain.com/parent/stuff-behind-parent
    or
    http://www.adomain.com/parent/stuff-...-parents-child
    and of course the homepage which is
    http://www.adomain.com/

    Now I want to parse the url and being left with only the parent name so I can use this in a switch. The parent is the only thing I need to know since this is the main menu...

    $current_url should be parsed to just the name... or something like that
    I'm now so far:

    PHP Code:
        $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
            
    : (":".$_SERVER["SERVER_PORT"]);
        
    $current_url $port.$_SERVER['REQUEST_URI'];

    switch (
    $current_url) {
        case 
    '/':
            echo 
    "Home";
            break;
        case 
    '/parent1':
            echo 
    "Parent1";
            break;
        case 
    '/parent2':
            echo 
    "Parent2";
            break;

    Hopefully somebody can help.
    Last edited by jaapoost; 10-20-2009 at 11:32 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,854
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    PHP Code:
    $req=explode('/',$_SERVER['REQUEST_URI']);
    print_r($req);
    switch(
    $req[1]){
     

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    jaapoost (10-20-2009)

  • #3
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    works like a charm! Cheers!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •