...

View Full Version : how to parse a URL



jaapoost
10-20-2009, 11:27 AM
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-behind-parent/stuff-behind-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:



$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.

abduraooft
10-20-2009, 11:38 AM
$req=explode('/',$_SERVER['REQUEST_URI']);
print_r($req);
switch($req[1]){

}

jaapoost
10-20-2009, 11:45 AM
works like a charm! Cheers!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum