Home > Backend Development > PHP Tutorial > PHP gets all links in the specified URL page

PHP gets all links in the specified URL page

WBOY
Release: 2016-07-25 08:42:26
Original
1297 people have browsed it
  1. //获取指定URL页面中所有链接
  2. function get_url_href($url){
  3. $html = file_get_contents($url);
  4. $dom = new DOMDocument();
  5. @$dom->loadHTML($html);
  6. $xpath = new DOMXPath($dom);
  7. $hrefs = $xpath->evaluate('/html/body//a');
  8. for($i=0;$i<$hrefs->length;$i++){
  9. $href = $hrefs->item($i);
  10. $url = $href->getAttribute('href');
  11. if(substr($url,0,4) == 'http') echo $url.'
    ';
  12. }
  13. }
复制代码

PHP, URl


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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template