Simple IF Statement To Call Class

Hi, i have just finished coding a design into html / css. I have spit the code up into php includes for the HEADER, NAVIGATION and the FOOTER

I have coded my navigation so that when a tab (page) is selected from navigation it has a different style. I have declared this style in the css called .selected

Can someone help me write a simple IF statement, that will work like this:

IF the current page is ‘contact.php’ echo ‘.selected’ ELSE do nothing

I was hoping to past this IF statement into the code for each tab / button so it would use the .selected class if it was on that page, thanks in advance for your help…

If the ELSE is doing nothing, you don’t need to include the ELSE portion.

Try this:



<html>
<body>

<?php
  switch( $_SERVER['REQUEST_URI'] )
  {
    case '/about.html'	: $selected = 'ff0';	 break;
    case '/blog.html'	: $selected = '0ff';	 break;
    case '/contact.html'	: $selected = 'f0f';	 break;
    case '/terms.html'	: $selected = 'f00'; break;
    case '/subscribe.html'	: $selected = '090'; break;
    default                         : $selected = '000';
  }
  $selected = 'style="background-color:#' .$selected .'"';
?>

  <div <?php echo isset($selected) ? $selected : NULL;?> >
   ...
   ...
  </div>

</body>
</html>


Beware: All Apache Versions are not the same. If on the off-chance $_SERVER[‘REQUEST_URI’] does not return the value expected then try this script:


  echo '<pre>';
    print_r( $_SERVER );
  echo '</pre>';
  die;

Cool, thanks all for your help…