PHP加粗搜索结果中关键字

WBOY
Release: 2016-06-20 13:02:25
Original
1196 people have browsed it

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

Copy after login


Related labels:
source:php.cn
Statement of this Website
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]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!