PHP DOM loadHtmlFile I/O 异常
我有以下代码片段 - echo'ing $msn 为我提供了预期的完整 html 输出。但是, $dom->loadHTMLFile 给了我一个例外:
警告:DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]:I/O 警告:无法加载外部实体
不确定我做错了什么?这是一段简单的代码..
$dom = new DOMDocument();
$msn = file_get_contents("http://moneycentral.msn.com/");
echo $msn;
echo "<br><br>";
$html = $dom->loadHTMLFile($msn);
I have the following code snippet - echo'ing $msn gives me the full html output as expected. However, the $dom->loadHTMLFile gives me an exception:
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O
warning : failed to load external entity
Not sure what i am doing wrong? Its a straightforward piece of code..
$dom = new DOMDocument();
$msn = file_get_contents("http://moneycentral.msn.com/");
echo $msn;
echo "<br><br>";
$html = $dom->loadHTMLFile($msn);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
loadHTMLFile 获取您尝试加载的文件的路径。您实际上所做的是将 HTML 标记作为参数传递给它。自然是失败了。
你需要做
或者
loadHTMLFile takes a path to the file you're trying to load. What you're actually doing is passing it the HTML markup as an argument. Naturally, it fails.
You need to either do
or
你想要的是
loadHTML
而不是 <代码>加载HTML文件。后者是打开一个文件,而不是文件的内容。$msn
的值包含内容,而不是文件本身的 URL。What you want is
loadHTML
and notloadHTMLFile
. The latter is to open a file, not the content of the file. The value of$msn
contains the content, and not the URL to the file itself.尝试这个构造:
Try this construction: