方法一
$url='http://www.google.cn/search?q=php';
$html=file_get_contents($url);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$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 />';
}
$url='http://www.google.cn/search?q=php';
$str=file_get_contents($url);
$preg='/<a .*?href=["|'](.*?)["|'].*?>/is';
preg_match_all($preg,$str,$array2);
for($i=0;$i<count($array2[1]);$i++)//逐个输出超链接地址
{
echo $array2[1][$i]."<br />";
}