PHP使用正則表達式清除超鏈接文本
可以用$str = preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$strhtml); 這段來實現(xiàn)需求,如果想要更多解決方法,可以參看以下的。
1、刪除內(nèi)容中的超鏈接
ereg_replace('<a([^>]*)>([^<]*)</a>','<font color="red">\\2</font>',$content);
ereg_replace("<a [^>]*>|<\/a>","",$content);
2、消除包含特定詞的超鏈接
$find="this string is my find";
$string='<font color="red">替換掉了</font>';//將超鏈接替換成的內(nèi)容
echo ereg_replace('<a([^>]*)>([^<]*'.$find.'[^>]*)</a>','<font color="red">\\2</font>',$content);
3、獲取超鏈接文本內(nèi)容
//方法一
preg_match_all('/<(a|a)[s]{0,1}[w=":()]*>[nrn]*(check user)[nrn]*</(a|a)>/i',$string,$matches);
//方法二
preg_match_all('/<a[dd]*>check user</a>/i',$string,$matches);
print_r($matches);
//方法三
preg_match_all('/<a[^>]*>[^<]*</a>/i',$string,$matches);
print_r($matches);
//方法四
preg_match_all('/<a.+?>check user</a>/is',$str,$arr);
print_r($arr);
//方法五
preg_match_all('/<a.+?>check user</a>/is',$str,$arr);
print_r($arr);
我用了這句 $year = preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$yearstr);
- php 正則表達式提取網(wǎng)頁超級鏈接url的函數(shù)
- PHP正則匹配圖片并給圖片加鏈接詳解
- 檢查url鏈接是否已經(jīng)有參數(shù)的php代碼 添加 ? 或 &
- php 正則 過濾html 的超鏈接
- php將url地址轉(zhuǎn)化為完整的a標(biāo)簽鏈接代碼(php為url地址添加a標(biāo)簽)
- phpMyAdmin 鏈接表的附加功能尚未激活問題的解決方法(已測)
- php 短鏈接算法收集與分析
- windows服務(wù)器下IIS6/7下PHP 無法加載 php_curl.dll 等動態(tài)鏈接庫
- php實現(xiàn)首頁鏈接查詢 友情鏈接檢查的代碼
- PHP 超鏈接 抓取實現(xiàn)代碼
- php正則表達式取得內(nèi)容所有鏈接的方法
- phpMyAdmin鏈接MySql錯誤 個人解決方案
- phpMyAdmin 鏈接表的附加功能尚未激活的問題
- php 自寫函數(shù)代碼 獲取關(guān)鍵字 去超鏈接
- PHP將頁面中點擊數(shù)量高的鏈接進行高亮顯示的方法
相關(guān)文章
PHP+Ajax實現(xiàn)上傳文件進度條動態(tài)顯示進度功能
這篇文章主要介紹了PHP+Ajax實現(xiàn)上傳文件進度條動態(tài)顯示進度功能,通過ajax實現(xiàn)主界面,php處理上傳文件,具體實例代碼大家跟隨腳本之家小編一起看看吧2018-06-06PHP 將數(shù)組打亂 shuffle函數(shù)的用法及簡單實例
下面小編就為大家?guī)硪黄狿HP 將數(shù)組打亂 shuffle函數(shù)的用法及簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06