在php编程中,偶然需要对一些html文本举行处置惩罚,比方需要将文本中的超链接内容去除,此时就需要用到正则表达式了。
能够运用:
$str = preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$strhtml);
下面来看几个PHP正则表达式消灭超链接文本的例了。(引荐进修:PHP编程从入门到通晓)
删除内容中的超链接
<?php ereg_replace('<a([^>]*)>([^<]*)</a>','<font color="red">\\2</font>',$content); ereg_replace("<a [^>]*>|<\/a>","",$content);
消弭包括特定词的超链接
<?php $find="this string is my find"; $string='<font color="red">替代掉了</font>';//将超链接替代成的内容 echo ereg_replace('<a([^>]*)>([^<]*'.$find.'[^>]*)</a>','<font color="red">\\2</font>',$content);
猎取超链接文本内容
<?php //要领一 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);
以上就是php中怎样把超文本链接作废的细致内容,更多请关注ki4网别的相干文章!