Jump to content

split URL and use in switch twice...??


jesushax

Recommended Posts

hi what im trying to do is split the current url

 

which i have below

 

then use the folder name in a switch and the page name in a switch

 

so if the current url is in a certain folder (folders listed in the switch case) then do something

but if the current url is in a certain page (pages listed in another switch) then do something

 

so is there something like switch else isntead of default?

of could i do an if statement to check it id the url is in any of listed folders then if true go to one switch if false go to another switch

 

can i have switches inside a if statement?

 

anyone understand me..? may be a little confusing lol

 

CHeers

 

<?php
$page = $_SERVER['REQUEST_URI'];
list($Root, $folder, $page) = split('[/]', $page);
switch(@$_GET["page"]) {

Case "about.php":
break;

default:
echo $page."<br/><br />";
echo "Root: $Root<br />Folder: $folder<br /> Page: $page<br />\n";
break;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/101520-split-url-and-use-in-switch-twice/
Share on other sites

can no one point me in the right direction here?

 

what it is im trying to do is

 

in my page header, for my css current page to work

i need to have the body identfied

 

as

<body id="home">

<body id="contact">

 

etc

 

so i need a way of determining what page we are currently on and set the body id to that page

 

problem is i have pages in subfolders and in my root folder

 

thanks

done it used a else if steamtment instead

 

$url = $_SERVER['REQUEST_URI'];
list($Root, $folder, $page) = split('[/]', $url);

if ($folder == "about.php")
{ echo '<body id="about">'; }
elseif ($page == "web.php")
{ echo '<body id="web">'; } 
elseif ($page == "marketing.php")
{ echo '<body id="marketing">'; } 
elseif ($page == "installations.php")
{ echo '<body id="installations">'; }
elseif ($folder == "portfolio")
{ echo '<body id="portfolio">'; } 
elseif ($folder == "contact.php")
{ echo '<body id="contact">'; } 
else 
{ echo '<body id="home">'; } 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.