示例#1
0
 /**
  *
  * @param unknown_type $content
  * @param unknown_type $word
  */
 public static function highlightWord($content, $word)
 {
     // list of separator
     $separator = array(' ', ' + ', ' - ', '~', '^', ' and ', ' or ', ' not ', '*', '"');
     // explode content
     $mycontent = explode(" ", $content);
     // group 1
     $group1 = explode(' ', $word);
     // group 2
     $group2 = str_ireplace($separator, ' ', $word);
     $group2 = explode(' ', $group2);
     // parse content
     foreach ($mycontent as $key => &$currentWord) {
         foreach ($group1 as $wordpart) {
             if ($wordpart == $currentWord || $wordpart == Sydney_Tools::stripAccents($currentWord)) {
                 $currentWord = '<strong>' . $currentWord . '</strong>';
                 continue 2;
             } else {
                 $currentWord = str_ireplace($wordpart, '<strong>' . $wordpart . '</strong>', $currentWord);
             }
         }
         foreach ($group2 as $wordpart) {
             if ($wordpart == $currentWord || $wordpart == Sydney_Tools::stripAccents($currentWord)) {
                 $currentWord = '<strong>' . $currentWord . '</strong>';
                 continue 2;
             } else {
                 $currentWord = str_ireplace($wordpart, '<strong>' . $wordpart . '</strong>', $currentWord);
             }
         }
     }
     // create string
     $content = implode(' ', $mycontent);
     return $content;
 }