首页  >  文章  >  后端开发  >  PHP加粗搜索结果中关键字

PHP加粗搜索结果中关键字

WBOY
WBOY原创
2016-06-20 13:02:251211浏览

function highlighter_text($text, $words){

$split_words = explode( " " , $words );

foreach($split_words as $word) {

$color = "#4285F4";

$text = preg_replace("|($word)|Ui" , "$1" , $text );

}

return $text;

}

$string = "I like chocolates and I like apples";$words = "apple";

echo highlighter_text($string ,$words);


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn