php 获取网页外部链接正则表达式
<?php preg_match_all("/<a(.*?)href=(.*?)</a>/i", $webContent, $link); $urls = array(); foreach ($link[0] as $value) { if (strstr($value, 'http')) { if (strstr($value, $ex[3]) || strstr($value, $ex[0]) || strstr($value, $ex[1]) || strstr($value, $ex[2])) { continue; } else { preg_match_all("/hrefs*=\s*([\'\"]?)(.*?)1/is", $value, $vlink); $urls[] = $vlink[2]; } } } $strUrl = deleteEmptyArray($urls); function deleteEmptyArray($val) { $links = ''; if (is_array($val)) { foreach ($val as $v => $_v) { if (!empty($_v[0])) { $links.= $_v[0] . '|'; } } return substr($links, 0, -1); } else { return false; } }
文章地址:http://www.phprm.com/code/b30cfa4d6004818104b3f07c0527a396.html
转载随意^^请带上本文地址!