Authored by 周少峰

搜索词高亮

... ... @@ -169,6 +169,7 @@ class HelperSearch
$gender = isset(self::$options['gender']) ? explode(',', self::$options['gender'])[0] : 0;
foreach($val['goods_list'] as $k => $v){
$goods_list[$k]['url'] = Helpers::getUrlBySkc($val['product_id'], $v['goods_id'], $val['cn_alphabet']);
//女封
if (isset($v['cover_1']) && $gender == 1) {
... ... @@ -187,7 +188,15 @@ class HelperSearch
if (!empty($val['default_images'])) {
$val['default_images'] = Images::getImageUrl($val['default_images'],$imgSize[0],$imgSize[1]);
}
//搜索关键字高亮
$patten = "/".self::$params['query']."/i";
if (isset(self::$params['query']) && !empty(self::$params['query']) && preg_match($patten, $val['product_name'], $match)) {
foreach ($match as $k => &$v) {
$replace[$k] = '<span style="color: #cc0000">'.$v.'</span>';
$v = '/'.$v.'/';
}
$val['product_name'] = preg_replace($match, $replace, $val['product_name']);
}
$good = array(
'tags' => array(
'isNew' => $isNew,
... ...