Jump to content

Ignore span tags in Preg Replace


gerkintrigg

Recommended Posts

hmm.

It's just that the span tag is created as I use my original script to replace a word (and highlight it) but then potentially goes over it again and highlights smaller words within the highlighted script.

 

so if I had a string like this:

this is the code to highlight

and the string is an exact phrase match for a record in the database, the script will replace and highlight it like this:

other text <span class="flagged_already"> this is the code to highlight</span> other text

That's all fine so-far but then it might match the word "code" too so that it outputs:

other text <span class="flagged_already"> this is the <span class="flagged_already">code</span> to highlight</span> other text

 

This could be an issue because it might over-highlight words like "you're" and "you".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.