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

PHP使用正則表達(dá)式清除超鏈接文本

 更新時(shí)間:2013年11月12日 15:13:12   投稿:zxhpj  
有些時(shí)候,我們需要對(duì)一些html文本進(jìn)行處理,比如需要將文本中的超鏈接內(nèi)容去除,這個(gè)時(shí)候就需要用到正則表達(dá)式

可以用$str = preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$strhtml); 這段來(lái)實(shí)現(xiàn)需求,如果想要更多解決方法,可以參看以下的。
1、刪除內(nèi)容中的超鏈接

復(fù)制代碼 代碼如下:

ereg_replace('<a([^>]*)>([^<]*)</a>','<font color="red">\\2</font>',$content);
ereg_replace("<a [^>]*>|<\/a>","",$content);

2、消除包含特定詞的超鏈接

復(fù)制代碼 代碼如下:

$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)容

復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評(píng)論