php正则取得网页上所有的链接

180it 2022-07-12 PM 725℃ 0条

本段代码是正则获取内容中的所有连接地址,这个在采集的时候经常用到

$con=  file_get_contents($url);
$pattern = '/<a(?:.*?)href="(((?:http(?:s?):\/\/)?([^\"\/]+))?(?:[^\"]*))"(?:[^>]*?)>([^<]*?)<\/a>/i';
preg_match_all($pattern, $con, $links);
$links = array_flip(array_flip($links[1]));

来源:http://www.3qphp.com/php/phpjch/2069.html

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php正则取得网页上所有的链接