我们再做爬虫爬取网页数据的时候,很多时候数据中带有对方的url地址,这个时候我们就需要将url链接地址给过滤掉,只保留链接的文本文字,以下是一个通过php进行url地址过滤的示例。
php如何过滤字符串中的url地址:
function removeLinks($str){
if(empty($str)) return '';
$str =preg_replace('/(http)(.)*([a-z0-9\-\.\_])+/i','',$str);
$str =preg_replace('/(www)(.)*([a-z0-9\-\.\_])+/i','',$str);
return $str;
}