Применить определенный класс / идентификатор к текущей странице в меню (PHP)

Error: User Rate Limit Exceeded

<div id="blahblah" style="blahblah">
<a href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
<a href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
<a href="http://domain.com/folder/gallery"><img style="blahblah" src="blahblahblahblah"></a>
<a href="http://domain.com/folder/dontknow"><img style="blahblah" src="blahblahblahblah"></a>
</div>

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

<div id="blahblah" style="blahblah">
<a <?php if (strpos($_SERVER['PHP_SELF'], 'biography')) echo 'class="current"';?> href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
<a <?php if (strpos($_SERVER['PHP_SELF'], 'contacts')) echo 'class="current"';?> href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
...
...
</div>

Error: User Rate Limit Exceeded

Ответы на вопрос(3)

Решение Вопроса

Error: User Rate Limit Exceeded

  1. check the result of strpos() with !== false.
  2. Use $_SERVER['REQUEST_URI'] rather than $_SERVER['PHP_SELF'].
  3. Wrap the code inside a function.

Error: User Rate Limit Exceeded

<?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>

Error: User Rate Limit Exceededstrpos()Error: User Rate Limit Exceeded

<?php $current = basename($path, ".php"); ?>

<a href="blahblah"<?php if ($current == 'biographies') echo ' class="current"'; ?> />

$currentError: User Rate Limit Exceeded.phpError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Ваш ответ на вопрос