PHP搜索和高亮字符串中的关键字
2018-07-20 来源:open-open
function highlighter_text($text, $words)
{
$split_words = explode( " " , $words );
foreach($split_words as $word)
{
$color = "#4285F4";
$text = preg_replace("|($word)|Ui" ,
"<span style=\"color:".$color.";\"><b>$1</b></span>" , $text );
}
return $text;
}
用法:
<?php $string = "I like chocolates and I like apples"; $words = "apple"; echo highlighter_text($string ,$words); ?>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:Hash线性探测法C++实现
下一篇:android多线程断点续传下载
最新资讯
热门推荐