Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $nav = <<<NAV
- <nav id="nav">
- <ul>
- <li><a href="/">Home</a></li>
- <li><a href="/section1/">Section 1</a></li>
- <li><a href="/section2/">Section 2</a></li>
- </ul>
- </nav>
- NAV;
- $lines = explode("n", $nav);
- foreach ($lines as $line) {
- $current = false;
- preg_match('/href="([^"]+)"/', $line, $url);
- if (substr($_SERVER["REQUEST_URI"], 0, 5) == substr(@$url[1], 0, 5)) {
- $line = str_replace('<a h', '<a class="active" h', $line);
- }
- echo $line."n";
- }
- ?>
- <?php
- $nav = <<<NAV
- <nav id="nav">
- <ul>
- <li><a href="/">Home</a></li>
- <li><a href="/section1/">Section 1</a>
- <ul>
- <li><a href="/section1/child-page-1">Child Page 1</a></li>
- <li><a href="/section1/child-page-2">Child Page 2</a></li>
- </ul>
- </li>
- <li><a href="/section2/">Section 2</a></li>
- </ul>
- </nav>
- NAV;
- $lines = explode("n", $nav);
- foreach ($lines as $line) {
- $current = false;
- preg_match('/href="([^"]+)"/', $line, $url);
- if (substr($_SERVER["REQUEST_URI"], 0, 5) == substr(@$url[1], 0, 5)) {
- $line = str_replace('<a h', '<a class="active" h', $line);
- }
- echo $line."n";
- }
- ?>
Add Comment
Please, Sign In to add comment