Highlight text, except html tags

Posted by Arjen on Stack Overflow See other posts from Stack Overflow or by Arjen
Published on 2010-04-07T08:50:07Z Indexed on 2010/04/07 8:53 UTC
Read the original article Hit count: 178

Filed under:
|
|

Hey,

I'm using the code below to highlight some keywords in a text:

$message = str_ireplace($words,'<span class="hightlighted_text">'.$words.'</span>',$message);

The text may contain some html tags, for example , etc..

How can I highlight "normal" text, except the text between the html tags? Because when users search for "img" the text will be highlighted and the image doesn't work anymore.

© Stack Overflow or respective owner

Related posts about php

Related posts about regex