最新消息: 新版网站上线了!!!

php查找出网页中所有链接

  1. $html = file_get_contents('http://www.example.com'); 
  2.  
  3. $dom = new DOMDocument(); 
  4. @$dom->loadHTML($html); 
  5.  
  6. // grab all the on the page 
  7. $xpath = new DOMXPath($dom); 
  8. $hrefs = $xpath->evaluate("/html/body//a"); 
  9.  
  10. for ($i = 0; $i < $hrefs->length; $i++) { 
  11.        $href = $hrefs->item($i); 
  12.        $url = $href->getAttribute('href'); 
  13.        echo $url.'<br />'

 

转载请注明:谷谷点程序 » php查找出网页中所有链接