maxert Posted December 7, 2006 Share Posted December 7, 2006 Hello,I have a two level submenu that looks something like this:[code]<ul><li><a href="/main-dir/subdir1/>1st Item</a></li><li><a href="/main-dir/subdir2/>2nd Item</a> <ul> <li><a href="/main-dir/subdir2/a.php>1st SubItem</a> <li><a href="/main-dir/subdir2/b.php>2nd SubItem</a> <li><a href="/main-dir/subdir2/c.php>3rd SubItem</a> </ul></li><li><a href="/main-dir/subdir3/>3rt Item</a></li><li><a href="/main-dir/subdir4/>4th Item</a></li></ul>[/code]I am indicating the active page by giving the relevant <li> a class of "active"The tricky part is that, in the case of SubItems I would like the parent <li> to have a class of "active" as well as the actual active page <li>.I have some code that is working on the main menu:[code]//Menu is $menu$lines = split("\n", $menu);foreach ($lines as $line) { $current = false; preg_match('/href="([^"]+)"/', $line, $url); if (substr($_SERVER["PHP_SELF"], 0, 5) == substr($url[1], 0, 5)) { $line = str_replace('<a h', '<a class="active" h', $line); } echo $line."\n";[/code]Can I modify this to work for my submenu?Thank you! Link to comment https://forums.phpfreaks.com/topic/29837-preg_match-php_self-and-adding-tag-elements/ Share on other sites More sharing options...
maxert Posted December 8, 2006 Author Share Posted December 8, 2006 If you can think of an alternate method that doesn't use the existing script, that would also be cool.Thanks! Link to comment https://forums.phpfreaks.com/topic/29837-preg_match-php_self-and-adding-tag-elements/#findComment-137593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.