PHP加粗搜索结果中关键字

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

<p>function highlighter_text($text, $words){</p><p>    $split_words = explode( " " , $words );</p><p>    foreach($split_words as $word)    {</p><p>        $color = "#4285F4";</p><p>        $text = preg_replace("|($word)|Ui" ,            "<b>$1</b>" , $text );</p><p>    }</p><p>    return $text;</p><p>}</p><p>$string = "I like chocolates and I like apples";$words = "apple";</p><p>echo highlighter_text($string ,$words);</p>
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template