$html = file_get_contents("http://www.somesite.com/");
$dom = new DOMDocument();
$dom->loadHTML($html);
echo $dom;
抛出
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity,
Catchable fatal error: Object of class DOMDocument could not be converted to string in test.php on line 10
发布于 2012-05-07 21:05:06
要取消警告,您可以使用libxml_use_internal_errors(true)
// create new DOMDocument
$document = new \DOMDocument('1.0', 'UTF-8');
// set error level
$internalErrors = libxml_use_internal_errors(true);
// load HTML
$document->loadHTML($html);
// Restore error level
libxml_use_internal_errors($internalErrors);
发布于 2011-02-23 09:24:00
我敢打赌,如果你查看http://www.somesite.com/
的源代码,你会发现一些特殊的字符还没有被转换成超文本标记语言。可能是这样的:
<a href="/script.php?foo=bar&hello=world">link</a>
应该是
<a href="/script.php?foo=bar&hello=world">link</a>
发布于 2010-10-16 13:28:31
$dom->@loadHTML($html);
这是不正确的,请使用以下命令:
@$dom->loadHTML($html);
https://stackoverflow.com/questions/1685277
复制相似问题