文章詳情頁
PHP 文章內(nèi)容中的關(guān)鍵詞替換加鏈接
瀏覽:69日期:2022-09-12 18:02:11
/** *對內(nèi)容中的關(guān)鍵詞添加鏈接 *只處理第一次出現(xiàn)的關(guān)鍵詞,對已有鏈接的關(guān)鍵不會再加鏈接,支持中英文 *$content:string 原字符串 *$keyword:string 關(guān)鍵詞 *$link:string,鏈接 */ public static function yang_keyword_link($content,$keyword,$link){ //排除圖片中的關(guān)鍵詞 $content = preg_replace( ’|(<img[^>]*?)(’.$keyword.’)([^>]*?>)|U’, ’$1%&&&&&%$3’, $content); $regEx = ’/(?!((<.*?)|(<a.*?)))(’.$keyword.’)(?!(([^<>]*?)>)|([^>]*?</a>))/si’; $url=’<a href='http://www.hdgsjgj.cn/bcjs/’.$link.’' target='_blank' class='content_guanjianci'>’.$keyword.’</a>’; $content = preg_replace($regEx,$url,$content,1); //還原圖片中的關(guān)鍵詞 $content=str_replace(’%&&&&&%’,$keyword,$content); return $content; }
標(biāo)簽:
PHP
相關(guān)文章:
1. Python TestSuite生成測試報告過程解析2. 增大python字體的方法步驟3. Spring security 自定義過濾器實現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實例代碼)4. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法5. Vue作用域插槽實現(xiàn)方法及作用詳解6. IntelliJ IDEA設(shè)置默認瀏覽器的方法7. JAMon(Java Application Monitor)備忘記8. Python os庫常用操作代碼匯總9. Python 如何展開嵌套的序列10. 如何清空python的變量
排行榜
