博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
核桃说笔记
阅读量:7226 次
发布时间:2019-06-29

本文共 1643 字,大约阅读时间需要 5 分钟。

点击展开看更多内容的效果:

{$answerx['author']}

{$answerx['time']}

部分内容。。。。。。

展开全部

 

搜索关键词高亮显示:公共方法

//srl 7-23 搜索覌點,覌點高亮变色修改function highlightDesc($content, $words, $highlightcolor = 'red') {    $wordlist = explode ( " ", $words );    foreach ( $wordlist as $hightlightword ) {        if (strlen ( $content ) < 1 || strlen ( $hightlightword ) < 1) {            return $content;        }        $content = preg_replace ( "/$hightlightword/is", "\\0", $content );    }    return $content;}

使用方法:控制器方法:使用上面方法进行高亮显示

//关键词搜索    function get_by_likename($word, $start = 0, $limit = 6) {        $topiclist = array ();        $query = $this->db->query ( "SELECT * FROM " . $this->db->dbprefix . "answer WHERE content like '%$word%' order by id desc LIMIT $start,$limit" );// var_dump($query->result_array ());die;        foreach ( $query->result_array () as $topic ) {            $topic ['title'] = checkwordsglobal ( $topic ['title'] );            $topic ['describtion'] = checkwordsglobal ( $topic ['content'] );            $topic ['title'] = highlightDesc ( $topic ['title'], $word );$topic ['describtion'] = highlightDesc (  strip_tags ( $topic ['content'] ), $word );$topiclist [] = $topic;        }        return $topiclist;    } 剥去字符串中的 HTML 标签:
strip_tags
页面中使用topiclist  函数遍历显示在页面中即可

 

转载于:https://www.cnblogs.com/yszr/p/10736344.html

你可能感兴趣的文章
猫头鹰的深夜翻译:Java 2D Graphics, 简单的仿射变换
查看>>
面试题:给你个id,去拿到name,多叉树遍历
查看>>
go append函数以及写入
查看>>
关于Java中分层中遇到的一些问题
查看>>
配置 PM2 实现代码自动发布
查看>>
android百种动画侧滑库、步骤视图、TextView效果、社交、搜房、K线图等源码
查看>>
iOS仿今日头条、壁纸应用、筛选分类、三方微博、颜色填充等源码
查看>>
诡异!React stopPropagation失灵
查看>>
Python_OOP
查看>>
个人博客开发系列:评论功能之GitHub账号OAuth授权
查看>>
mongodb--安装和初步使用教程
查看>>
ES6简单总结(搭配简单的讲解和小案例)
查看>>
text-decoration与color属性
查看>>
如何使用Mybatis第三方插件--PageHelper实现分页操作
查看>>
PyCharm搭建GO开发环境(GO语言学习第1课)
查看>>
Android交互
查看>>
提醒我喝水chrome插件开发指南
查看>>
列表数据转树形数据
查看>>
Java新版本的开发已正式进入轨道,版本号18.3
查看>>
从零开始的webpack生活-0x009:FilesLoader装载文件
查看>>