时间: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);