You should:
strpos()
with !== false
.$_SERVER['REQUEST_URI']
rather than $_SERVER['PHP_SELF']
.Something like this:
<?php
function get_current($name) {
if (strpos($_SERVER['REQUEST_URI'], $name) !== false)
echo 'class="current"';
}
?>
<div id="blahblah" style="blahblah">
<a <?php get_current('biography') ?> href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
<a <?php get_current('contacts') ?> href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
...
...
</div>
if the position is 0, then it will evaluate to FALSE in PHP. You should check the return value specifically, i.e. >= 0.
Instead of strpos()
, you could try this:
<?php $current = basename($path, ".php"); ?>
<a href="blahblah"<?php if ($current == 'biographies') echo ' class="current"'; ?> />
$current
is the name of the current file, without the .php
extension.