不能加载和解析DOM对象


Can't Load And Parse DOM Object

我正在尝试加载一个dom对象并解析它以查找特定的链接
下面是我的代码:

$content = file_get_contents("http://www.example.com/example.php");
$dom = new DOMDocument();
$dom->loadHTML($content);
$dom->preserveWhiteSpace = false; 
 var_dump($dom);

我得到的是:

object(DOMDocument)#1 (0) {}

如果我回显$content,我得到所有的html。

我的代码有什么问题?

这是一个来自手册的例子:

<?php 
$content = file_get_contents("http://www.example.com/example.php");
$xml = new DOMDocument();
$xml->loadHTML($content);
// Empty array to hold all links to return
$links = array();
//Loop through each <a> tag in the dom and add it to the link array
foreach($xml->getElementsByTagName('a') as $link) {
    $links[] = array('url' => $link->getAttribute('href'), 'text' => $link->nodeValue);
}
print_r($links);
?>

代替var_dump($xml)试一试:echo $ xml -> saveHTML ();