Guest User

Untitled

a guest
Oct 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. private function highlight($words, $str) {
  2.  
  3.         $highlight = '<span class="highlight">$0</span>';
  4.         $pattern = '#(?!<.*?)(%s)(?![^<>]*?>)#i';
  5.         foreach ($words as $word) {
  6.             $word = preg_quote($word);
  7.             $regex = sprintf($pattern, $word);
  8.             $str = preg_replace($regex, $highlight, $str);
  9.         }
  10.         return $str;
  11.     }
Add Comment
Please, Sign In to add comment