欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php查找任何頁(yè)面上的所有鏈接的方法

 更新時(shí)間:2013年12月03日 17:40:23   作者:  
php查找頁(yè)面上的所有鏈接該怎么實(shí)現(xiàn)?使用DOM就可以輕松從任何頁(yè)面上抓取鏈接,下面有個(gè)不錯(cuò)的示例,感興趣的朋友可以參考下
使用DOM,你可以輕松從任何頁(yè)面上抓取鏈接,代碼示例如下:
復(fù)制代碼 代碼如下:

$html = file_get_contents('http://www.example.com');
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
echo $url.'<br />';
}

相關(guān)文章

最新評(píng)論