PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
You mean not include it in your comments? I think what you want to do is remove them from your comments after the comments have been highlighted, or you'll have highlighted text inside of highlighted text (which takes precedence in HTML).
Check the regex that determines if something is in a comment, combined with regex if something is an HTML tag. However, you only want to select the HTML tags for replacement. Here's the regex for an html tag (I think).
Want you want is to check if it's an HTML tag, and check if it's in comments, then delete it. You don't need to check both tags. I'm pretty sure the pattern I cave you works for either.
You don't want to get rid of what's in the tags, just the individual tags themselves.
And take noticed that I edited my early regex to include + on the [^>] character class.
Oh, what's going on is that the regex I gave you replaces the first occurrence of any HTML tag inside of the comments. That includes the <br /> tag. You'd have to ignore the <br />. As for removing more than one tag... I don't know. preg_match_all(), maybe?
Example 1674. Find matching HTML tags (greedy)
<?php
// The \\2 is an example of backreferencing. This tells pcre that
// it must match the second set of parentheses in the regular expression
// itself, which would be the ([\w]+) in this case. The extra backslash is
// required because the string is in double quotes.
$html = "<b>bold text</b><a href=howdy.html>click me</a>";