可以用$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);
新聞熱點(diǎn)
疑難解答