Jump to content

preg_replace highlight search terms- how to disregard URLs?


immanuelx2

Recommended Posts

hey all.

 

I currently have a preg_replace function to highlight search terms with the following:

<?php $article_text = preg_replace("/\b(".$_GET['search'].")\b/i", '<span style="background:#ffffab">\1</span>', $article['text']);

 

However, the problem is that if a URL using bbcode (ex. Link) contains the search keyword, it will wrap <span> around it and mess up the link.  Is there any way I can add to the regexp where "search term" is NOT between "" ?

 

Thanks in advance

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.