当前位置:Gxlcms > PHP教程 > PHP加粗搜索结果中关键字

PHP加粗搜索结果中关键字

时间:2021-07-01 10:21:17 帮助过:14人阅读

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);

人气教程排行