I need to modify HTML markup such that a matched word or phrase gets hightlighted, but that phrase may contain markup. For example:
This formatted text :
This <b>f<i>or</i>mat</b>ted text
I'd want to be able to find "This formatted" and wrap it in <style="color:lightblue" </span>
tags
So the above would become:
<span style="color:yellow">This <b>f<i>or</i>mat</b>ted</span> text
I'm using PHP on linux.
Thanks
EDIT: I'm not looking to replace tag but match text that has tags within it. Basically matching a string that may be spaced out with arbitrary tags of any type or length. Please ignore my ancient html tags, they were just easier to type.
If I'm understanding the question correctly, you could use preg_match to find the specified string, then replace it with a version surrounded by your tag.