What are some common methods for highlighting navigation using PHP?
One common method for highlighting navigation using PHP is to add a CSS class to the active navigation link. This can be achieved by checking the current page URL against the navigation link URLs and adding the active class accordingly.
<?php
$current_page = basename($_SERVER['REQUEST_URI']);
$nav_links = array(
'index.php' => 'Home',
'about.php' => 'About',
'services.php' => 'Services',
'contact.php' => 'Contact'
);
foreach ($nav_links as $url => $label) {
$class = ($current_page == $url) ? 'active' : '';
echo '<li><a href="' . $url . '" class="' . $class . '">' . $label . '</a></li>';
}
?>