Remove String from $_SERVER[SCRIPT_NAME}
Posted: Sat Aug 21, 2010 7:45 am
Hello,
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:
I'm looking for a solution that allows me to ditch the $bodyID method I'm currently using so I can take advantage of the SCRIPT_NAME variable to do the same thing in a more efficient manner.
I have a separate include that I call into all pages, and I'm thinking this would be the place to define something like this...
And then my navigation would once again look like this (without having to define the $bodyID variable on EVERY page of the site):
I'd truly appreciate any help with the "do something to $_SERVER[SCRIPT_NAME] to remove directory path and file extension ;" statement from above.
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>