Jump to content

Style based on URL with "_" seperator


robbluther

Recommended Posts

Here is my question... I want to assign a specific style based on part of the URL. So, if my URLs start: /section_page, I want to know the /section and assign a style to it.

 

I am using:

<style type="text/css" media="screen">

@import "../styles/nav.php";

</style>

 

to Import my PHP style... I need to know how to rip apart the URL and test for the "section".

 

Any help would be appreciated.

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/112767-style-based-on-url-with-_-seperator/
Share on other sites

You should look up on exploding strings into arrays:

 

http://us3.php.net/manual/en/function.explode.php

 

You can use that to do:

 

$array = explode("/", $_SERVER['REQUEST_URI']);

 

then access the $array[1] or $array[2] or where ever your "section" part happens.

Ok...  one more issue...  I am trying to post this code in my .php file to manipulate my DIV classes... when it is in the head or the body my page does not load at all.

 

<?php
$page = $_SERVER['PHP_SELF'];
$parts = explode('_',$page);

if($parts[0] == '/traditional.php' || '/traditional'){

$style = 'activeList';

}elseif{
($parts[0] == '/utility.php' || '/utility'){

$style = 'activeList';
}else{
$style = '';
}
?>

 

 

Thanks again guys!

 

<!------------------------- UPDATE - Sorry it was a stupid Typo ------------------------------------->

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.