Hi,
i'm developping a php-based site, and I'm stuck on the following;
I have sever links placed in a list like this:
Now, i want to find the right <li>....</li> line that contains the name (whatever, anotherwhatever, home...) so i can replace it with <li class="active>whatever</li>.Code:<ul> <li class="active">Home</li> <li><a href="whatever.php">whatever</a></li> <li><a href="whatever.php?id=3623">anotherwhatever</a></li> .... </ul>
I know I need to use preg_replace for this (since you can't simply use a wildcard with str_replace, en de href attrib isn't constant), But my Regular expression skills seem to be lacking.
This is what I've got (and obviously doesn't work):
Code:$pattern = '/<li><a href="[^>]*">'.$row["name"].'</a></li>/'; $template = preg_replace($pattern, "<li class='active'>".$row['name']."</li>", $template); echo $template;
Any help would be muchly appreciated!




Reply With Quote