SimpleXML 抛出警告 - 如何捕获?
我在确定 simplexml_load_string()
发生了什么时遇到了一些麻烦,我正在使用下面的代码来呈现一些 XML....当我运行此代码时,我收到如下错误消息:
Message: simplexml_load_string() [function.simplexml-load-string]: Entity: line 94: parser error : Opening and ending tag mismatch: meta line 15 and head
Any ideas on我怎样才能捕捉到这些警告? libxml_get_errors
没有影响。
$response = simplexml_load_string($response);
var_dump($response);
if (count(libxml_get_errors()) > 0) {
print_r(libxml_get_errors());
}
if (is_object($response)) { //returns true when warnings are thrown
//process response
} else {
//record error
}
I'm having some trouble determining what's going on with simplexml_load_string()
I'm using the below code to render some XML.... when I run this code I get error messages like:
Message: simplexml_load_string() [function.simplexml-load-string]: Entity: line 94: parser error : Opening and ending tag mismatch: meta line 15 and head
Any ideas on how I can catch these warnings? libxml_get_errors
has no affect.
$response = simplexml_load_string($response);
var_dump($response);
if (count(libxml_get_errors()) > 0) {
print_r(libxml_get_errors());
}
if (is_object($response)) { //returns true when warnings are thrown
//process response
} else {
//record error
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
其他解决方案,在 PHP 中,您可以使用错误控制运算符(
@
)忽略任何错误消息,在这种情况下:祝你好运!
Other solution, in PHP you can ignore any error messages usign the error control operator(
@
), in this case:Good luck!
在我的情况下,共享 XML 的服务器将其 http 更改为 https。因此,我们正在下载旧路径 XML 文件,在本例中该文件已“损坏”。这就是我们出现错误的原因。
XML 文件加载完美,因为我没有注意到 https 问题(浏览器重定向)。
In my situation server which was sharing XML changed their http to https. Because of that we were downloading old path XML file, which in this case was "corrupted". That is why we had the error.
XML files was loading perfectly because of that i didn't noticed https problem ( browser redirect ).