這篇文章將為大家詳細(xì)講解有關(guān)如何在PHP中利用正則表達(dá)式清除超鏈接文本,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
可以用$str = preg_replace("/]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$strhtml); 這段來(lái)實(shí)現(xiàn)需求,如果想要更多解決方法,可以參看以下的。
1、刪除內(nèi)容中的超鏈接
ereg_replace(']*)>([^<]*)','\\2',$content); ereg_replace("]*>|<\/a>","",$content);
2、消除包含特定詞的超鏈接
$find="this string is my find"; $string='替換掉了';//將超鏈接替換成的內(nèi)容 echo ereg_replace(']*)>([^<]*'.$find.'[^>]*)','\\2',$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('/check user/i',$string,$matches);print_r($matches); //方法三preg_match_all('/]*>[^<]*/i',$string,$matches);print_r($matches); //方法四preg_match_all('/check user/is',$str,$arr);print_r($arr); //方法五preg_match_all('/ check user/is',$str,$arr);print_r($arr); 我用了這句 $year = preg_replace("/]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$yearstr);
關(guān)于如何在PHP中利用正則表達(dá)式清除超鏈接文本就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。