欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php批量刪除超鏈接的實現(xiàn)方法

 更新時間:2015年10月19日 16:45:20   投稿:lijiao  
有時候我們會遇到這種需求,清除掉一段html文本內容中的超鏈接,這時有什么好辦法呢?下面就總結幾種簡單的方法清除html文本中的超鏈接,需要的朋友可以參考下

清除掉一段html文本內容中的超鏈接最常見的寫法可以如下:

復制代碼 代碼如下:
$str=preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$content);

1、刪除html文本內容中的超鏈接
復制代碼 代碼如下:
ereg_replace("<a [^>]*>|<\/a>","",$content);

2、清除包含指定關鍵詞的超鏈接

$find="this string is my find"; 
$string='<font color="red">這段內容將要被替換掉</font>';//將超鏈接替換成的內容 
echo ereg_replace('<a([^>]*)>([^<]*'.$find.'[^>]*)</a>','<font color="red">\\2</font>',$content); 

下面同時分享幾種獲取html文本內容中的超鏈接的文本內容方法:

//方法一 
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); 
 

以上就是php批量刪除超鏈接的四種方法,希望對大家的學習有所幫助。

相關文章

最新評論