Jump to content

preg_replace problem


robert_gsfame

Recommended Posts

i have this function to highlight search text

 

function highlightWords($text, $words)

{

          foreach ($words as $word)

        {

              $word = preg_quote($word);

              $text = preg_replace("/\b($word)\b/i", '<span class="highlight_word">\1</span>', $text);

        }

      return $text;

}

 

?>

if i want to highlight let say "Mr" and "George" from

"Let me introduce you to Mr George"

 

I found that the word George missing after the word "Mr" highlighted

 

Link to comment
https://forums.phpfreaks.com/topic/207605-preg_replace-problem/
Share on other sites

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.