I\'m using the code below to highlight some keywords in a text:
$message = str_ireplace($words,\'\'.$words.\'
Use a DOM parser of some sort. This is not something you want to do with regex.