gerkintrigg Posted November 19, 2009 Share Posted November 19, 2009 is there a way of telling a preg replace function that it is to ignore the text within a tag like this: this text is fair game to be replaced by the function <span class="flagged_already">but this is not</span>, this is though. Link to comment https://forums.phpfreaks.com/topic/182216-ignore-span-tags-in-preg-replace/ Share on other sites More sharing options...
emopoops Posted November 19, 2009 Share Posted November 19, 2009 no but u can use this: <?php $text = your string containing the span tage; $html = array('<span class="flagged_already">', '</span>'); $replacements = array ('', '');///replace with nothing $text = str_replace($html, $replacements, $text); ?> Link to comment https://forums.phpfreaks.com/topic/182216-ignore-span-tags-in-preg-replace/#findComment-961521 Share on other sites More sharing options...
gerkintrigg Posted November 20, 2009 Author Share Posted November 20, 2009 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". Link to comment https://forums.phpfreaks.com/topic/182216-ignore-span-tags-in-preg-replace/#findComment-961751 Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 if its the sama span tag the i think your good Link to comment https://forums.phpfreaks.com/topic/182216-ignore-span-tags-in-preg-replace/#findComment-962252 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.