PHP DOMDocument loadHTML 错误

Ste*_*ess 3 html php parsing dom domdocument

它回来了

( ! ) 警告: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);

?>
Run Code Online (Sandbox Code Playgroud)

出于某种原因,它不会解析 $content。如果我使内容像 $content = ""; 我通过元素标签名称解析它它没有问题但是如果我给它返回 file_get_content() 方法它会产生那个错误。

file_get_contents() 的文档说它返回一个字符串但由于某种原因它不起作用我什至尝试过 $content = (string)file_get_contents($url);

同样的事情提前感谢所有的帮助。

Kur*_*sen 6

在许多情况下,建议使用libxml_use_internal_errors(true);$dom->loadHTML($content);

这样就不会抛出警告,无论如何都会加载页面。