Home >php教程 >PHP源码 >取得所有链接

取得所有链接

PHP中文网
PHP中文网Original
2016-05-25 17:14:341036browse

这篇文章主要介绍了php获取网页上所有链接的方法,涉及php操作正则匹配的技巧,代码简单实用,需要的朋友可以参考下,具体实现方法如下:

<?php
function get_all_url($code){ 
    preg_match_all(&#39;/<as+href=["|&#39;]?([^>"&#39; ]+)["|&#39;]?s*[^>]*>([^>]+)</a>/i&#39;,$code,$arr); 
    return array(&#39;name&#39;=>$arr[2],&#39;url&#39;=>$arr[1]); 
}
?>

希望本文所述对大家的php程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Quentin Zervaas's DBONext article:PHP抓取网页的函数