Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-20-2009, 11:27 AM   PM User | #1
jaapoost
New to the CF scene

 
Join Date: Oct 2009
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
jaapoost is an unknown quantity at this point
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..
jaapoost is offline   Reply With Quote
Old 10-20-2009, 11:38 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
PHP Code:
$req=explode('/',$_SERVER['REQUEST_URI']);
print_r($req);
switch(
$req[1]){
 

__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
jaapoost (10-20-2009)
Old 10-20-2009, 11:45 AM   PM User | #3
jaapoost
New to the CF scene

 
Join Date: Oct 2009
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
jaapoost is an unknown quantity at this point
works like a charm! Cheers!
jaapoost is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:42 AM.


Advertisement
Log in to turn off these ads.