This is my first post to this forum, and my first foray into PHP SERVER variables. I'm trying to dynamically create a class (CSS) in my main navigation based on the SCRIPT_NAME variable. In order to do so, I'd like to strip the directory path preceding the file name and the ".php" that follows.
This:
../directory/index.php
Becomes:
index
Taking a step back...
I've been defining a $bodyID variable on each page and have been using that as a trigger. For instance:
Code: Select all
<?php $body="index"; ?>
<ul>
<li><a href="index.php" <?php if($bodyID == "index") {print 'class="active"';} ?>>Home</a></li>
...
</ul>
Code: Select all
<ul>
<li><a href="index.php" <?php if($_SERVER[SCRIPT_NAME] == "index") {print 'class="active"';} ?>>Home</a></li>
...
</ul>
Code: Select all
<?php $bodyID = do something to $_SERVER[SCRIPT_NAME] to remove directory path and file extension ; ?>
Code: Select all
<ul>
<li><a href="index.php" <?php if($bodyID == "index") {print 'class="active"';} ?>>Home</a></li>
...
</ul>