`
andrew1024
  • 浏览: 71323 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

thinkphp搜索里关键字变红色字体

阅读更多
//获取查询结果
        $type = $_POST['type']?$_POST['type']:$_COOKIE['type'];
        $keyword = trim($_POST['keyword'])?trim($_POST['keyword']):$_COOKIE['keyword'];
        setcookie('type',$type);
        setcookie('keyword',$keyword);

        $this->assign('keyword',$keyword);
        $this->assign('type',$type);
        //搜索新闻
        if($type==1){
            $news = D('News');
            $count=$news->where("ischecked=1 and subject like '%$keyword%'")->count($data);
    import("@.ORG.Page");
        $p=new page($count,12);
        $list=$news->where("ischecked=1 and subject like '%$keyword%'")->order('id desc')->limit($p->firstRow.','.$p->listRows)->findAll();
$i = 0;
foreach($list as $vo){
$content = $vo['subject'];
$list[$i++]['subject']=str_ireplace($keyword,"<font color='#FF0000'>".$keyword."</font>",$content);  //关键字红色字体
}
        $page=$p->show();
   if ($list!==false) {
$this->assign('page',$page);
$this->assign('list',$list);
$this->assign('count',$count);
            }
         }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics