SimpleXML 似乎没有加载任何东西...?
这真让我困惑。我以前从未使用过 XML,所以我只是在玩(当然是半夜......!)
代码:
$xml_string = "<?xml version="1.0" encoding="utf-8" ?><result>
<status>fail</status>
<error>
<code>192</code>
<message>Previous command still being processing</message>
</error>
</result>"
$rss = simplexml_load_string($xml_string);
print $rss->result->status;
我有点困惑......我读过的每个教程似乎都表明这一点这将打印“失败” - 但它没有......?有人能指出我正确的方向吗?
This is really baffling me. I've never used XML before, so I'm just playing about (it's the middle of the night of course...!)
The code:
$xml_string = "<?xml version="1.0" encoding="utf-8" ?><result>
<status>fail</status>
<error>
<code>192</code>
<message>Previous command still being processing</message>
</error>
</result>"
$rss = simplexml_load_string($xml_string);
print $rss->result->status;
I'm kinda baffled... Every tutorial that I have read seems to suggest that this will print "fail" - but yet it doesn't...? Can someone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一些错误:
引号,但有未转义的双引号
字符串内的引号
提前终止你的字符串。到
解决这个问题要么逃避双重
字符串内的引号或使用
单引号或此处文档。
result
节点是要打印
fail
文档,您需要:查看
为提示您始终可以通过执行
print_r($rss);
转储 XML 对象的内容There are some errors:
quotes but there are unescaped double
quotes inside the string which
prematurely terminate your string. To
fix this either escape the double
quotes inside the string or use
single quote or here doc.
The
result
node is the root of thedocument so to print
fail
you need:See it
As a tip you can always dump the content of the XML object by doing
print_r($rss);