tp6 搜索的关键词 高亮变色

//控制器:		
$list = DataModel::with('User')->where($map)->order(['id'=>'desc'])->where('deletetime',0)->where('status',2)->page($page)->paginate(['list_rows'=>10,'query' => request()->param()]);

foreach ($list as $k=>$v){
			if($v['title']){
				// pattern  要替换的关键字
				//  replacement   要替换的内容
				// subject  被替换的字符串
				$str = $v['title'] = preg_replace("/($keywords)/i","\\1",$v['title']);
				// $str=str_replace($keywords,"$keywords",$v['title']);
				$list[$k]['title'] = $str;
			}
		}



//模板:{$vo.title|raw}

你可能感兴趣的:(PHP,php)