它返回:
(!) 警告:DOMDocument :: loadHTML()[domdocument.loadhtml]:在实体中放置了错位的DOCTYPE声明,行:3,位于C:\ wamp \ www \ source.php的第8行
代码:
<?php
$url = "http://www.some-plain-html-website.com";
$content = file_get_contents($url);
$dom = new DOMDocument;
$dom->loadHTML($content);
?>
由于某种原因,它无法解析$content。如果我将$content设置为字符串,例如$content = ""; 并通过元素标记名称解析它,那么没有问题,但是如果我给它file_get_content()方法的返回值,它会产生错误。
file_get_contents()的文档说明它返回一个字符串,但出现了问题,我甚至尝试了$content = (string)file_get_contents($url);
同样的问题,提前感谢所有的帮助。