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

取得所有链接

PHP中文网
Release: 2016-05-25 17:14:34
Original
1037 people have browsed it

这篇文章主要介绍了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]); 
}
?>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template