$doc = new DOMDocument();
if ($doc->load('http://foo.com/bar.xml')) {
// good
} else {
// wtf happened?
}
I can wget http://foo.com/bar.xml
from the location where the PHP code is running, so I know the URL is accessible. I'm thinking it must be something other than an HTTP error.
我可以从PHP代码运行的位置获取http://foo.com/bar.xml,因此我知道URL是可访问的。我想一定是HTTP出错了。
I'm not sure what else could be causing the failure. Maybe a parsing issue? The XML appears to be valid (and passes W3C's validation test). As far as I can tell from the documentation, there's no way to determine why the load failure occurred.
我不确定还有什么可能导致失败。也许一个解析的问题?XML看起来是有效的(并且通过了W3C的验证测试)。从文档中我可以看出,没有办法确定为什么会发生负载故障。
Here's the XML:
这是XML:
<response>
<version>8</version>
<minversion>1</minversion>
<url>api.asp?</url>
</response>
2 个解决方案
#1
4
I finally narrowed it down to a PHP configuration setting called allow_url_fopen
, which was set to Off
on the server running the script.
我最终将它缩小到一个名为allow_url_fopen的PHP配置设置,它在运行脚本的服务器上设置为Off。
I modified the php.ini
file to enable this setting:
我修改了php。ini文件启用此设置:
allow_url_fopen = On
And now DOMDocument.load
can load XML from a remote URL.
现在DOMDocument。load可以从远程URL加载XML。
WARNING: apparently there are some security issues with keeping this setting on permanently.
警告:显然,将此设置永久打开存在一些安全问题。
#2
2
Add this:
添加:
libxml_use_internal_errors ( true );
$doc = new DOMDocument();
$doc -> recover = true;
$doc -> strictErrorChecking = false;
#1
4
I finally narrowed it down to a PHP configuration setting called allow_url_fopen
, which was set to Off
on the server running the script.
我最终将它缩小到一个名为allow_url_fopen的PHP配置设置,它在运行脚本的服务器上设置为Off。
I modified the php.ini
file to enable this setting:
我修改了php。ini文件启用此设置:
allow_url_fopen = On
And now DOMDocument.load
can load XML from a remote URL.
现在DOMDocument。load可以从远程URL加载XML。
WARNING: apparently there are some security issues with keeping this setting on permanently.
警告:显然,将此设置永久打开存在一些安全问题。
#2
2
Add this:
添加:
libxml_use_internal_errors ( true );
$doc = new DOMDocument();
$doc -> recover = true;
$doc -> strictErrorChecking = false;