多个或者单个关键词高亮

    /**
     * @param $need
     * @param $key_word //关键词 $fk=('123','kkk');
     * @return mixed
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @name: replace
     * @describe:多个或者单个关键词高亮显示
     */
function replace_keys($need,$key_word){
    if(empty($key_word)){
        return $need;
    }
    $s=@explode(",",$key_word);
    if(count($s) >1){
        $arr=[];
        foreach($s as $k=>$v){
            $arr[$k]="<b style='color:#6483ff;font-weight: bold;font-size: large;'>{$v}</b>";
        }
        $res=str_ireplace($s,$arr,$need);
    }else{
        $res = str_ireplace($key_word,"<b style='color:#6483ff;font-weight: bold;font-size: large;'>{$key_word}</b>",$need);
    }
    return $res;
}

评论

(= ̄ω ̄=)··· 暂无内容!

回复

您还未登录,请先登录或者注册

微信扫一扫
关注该公众号