文章详情页
PHP 文章内容中的关键词替换加链接
浏览:141日期:2022-09-12 18:02:11
/** *对内容中的关键词添加链接 *只处理第一次出现的关键词,对已有链接的关键不会再加链接,支持中英文 *$content:string 原字符串 *$keyword:string 关键词 *$link:string,链接 */ public static function yang_keyword_link($content,$keyword,$link){ //排除图片中的关键词 $content = preg_replace( ’|(<img[^>]*?)(’.$keyword.’)([^>]*?>)|U’, ’$1%&&&&&%$3’, $content); $regEx = ’/(?!((<.*?)|(<a.*?)))(’.$keyword.’)(?!(([^<>]*?)>)|([^>]*?</a>))/si’; $url=’<a href='https://www.haobala.com/bcjs/’.$link.’' target='_blank' class='content_guanjianci'>’.$keyword.’</a>’; $content = preg_replace($regEx,$url,$content,1); //还原图片中的关键词 $content=str_replace(’%&&&&&%’,$keyword,$content); return $content; }
标签:
PHP
上一条:PHP将人民币中金额数字转化为中文大写代码下一条:PHP视频教程文档教程
相关文章:
1. android studio新手如何创建项目?androidstudio的使用方法2. JAVA教程:解析Java的多线程机制(6)3. python+excel接口自动化获取token并作为请求参数进行传参操作4. bootstrap select2 动态从后台Ajax动态获取数据的代码5. asp(vbscript)中自定义函数的默认参数实现代码6. SpringMail使用过程中的报错解决办法7. web开发者不可错过的11个JavaScript工具8. 使用python采集Excel表中某一格数据9. Android AS为xutils添加依赖过程图解10. python 实现在无序数组中找到中位数方法
排行榜

网公网安备