Home  >  Article  >  Backend Development  >  PHP加粗搜索结果中关键字

PHP加粗搜索结果中关键字

WBOY
WBOYOriginal
2016-06-20 13:02:251203browse

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]