分享

搜索结果检测关键字高亮显示

 丶平上 2017-05-15
  1. //高亮显示函数  
  2. function bat_highlight($message,$words,$color = '#ff0000'){  
  3.     if(!empty($words)){  
  4.         $highlightarray = explode('+',$words);  
  5.         $sppos = strrpos($message,chr(0).chr(0).chr(0));  
  6.         if($sppos!==FALSE){  
  7.             $specialextra = substr($message,$sppos+3);  
  8.             $message = substr($message,0,$sppos);  
  9.         }  
  10.         $message = preg_replace(array("/(^|>)([^<]+)(?=<|$)/sUe","/<highlight>(.*)<\/highlight>/siU"),array("\highlight('\\2', \$highlightarray, '\\1')","<strong><font color=\"$color\">\\1</font></strong>"),$message);  
  11.         if($sppos!==FALSE){  
  12.             $message = $message.chr(0).chr(0).chr(0).$specialextra;  
  13.         }  
  14.     }  
  15.     return $message;  
  16. }  
  17. function highlight($text, $words, $prepend) {  
  18.     $text = str_replace('\"', '"', $text);  
  19.     foreach($words AS $key => $replaceword) {  
  20.         $text = str_replace($replaceword, '<highlight>'.$replaceword.'</highlight>', $text);  
  21.     }  
  22.     return "$prepend$text";  
  23. }  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多