Grabbing and matching filename from URI (using a function)
Posted: Sun Mar 15, 2009 11:59 am
Hi, I'm new to PHP (previously used ASP, Coldfusion and JavaScript for work) and am having difficulty with the function below.
At the moment the function is outside of the a tag, I will move this just as soon as I can work out why it's not working. I am outputting the urlsection and section variables just so I can check they're the same. They are. 
My URL looks like: http://localhost/ashalondon/ourmission.php
All help gratefully received! Thanks, K
Code: Select all
<?php
$urlsection = trim(basename($_SERVER["REQUEST_URI"],".php"));
echo "[urlsection: " . trim($urlsection) . "]";
function checksection($section) {
echo "[section: " . $section . "]";
if ($section == $urlsection) {
echo " class='lit'";
}
}
?>
<ul>
<li><a href="ourmission.php"><?php checksection("ourmission")?>Our Mission</a></li>
<li><a href="contribute.php"><?php checksection("contribute")?>Contribute</a></li>
<li><a href="projects.php"><?php checksection("projects")?>Projects</a></li>
<li><a href="news.php"><?php checksection("ourmission")?>News</a></li>
<li><a href="events.php">Events</a></li>
<li><a href="contactus.php">Contact us</a></li>
</ul>My URL looks like: http://localhost/ashalondon/ourmission.php
All help gratefully received! Thanks, K