SimpleXML 似乎没有加载任何东西...?

发布于 2024-10-09 05:45:16 字数 517 浏览 1 评论 0原文

这真让我困惑。我以前从未使用过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱&纷飞 2024-10-16 05:45:16

有一些错误:

  • 您正在以双引号引用字符串
    引号,但有未转义的双引号
    字符串内的引号
    提前终止你的字符串。到
    解决这个问题要么逃避双重
    字符串内的引号或使用
    单引号或此处文档。
  • result 节点是
    要打印 fail 文档,您需要:

    print $rss->status;
    

查看

为提示您始终可以通过执行 print_r($rss); 转储 XML 对象的内容

There are some errors:

  • You are quoting your string in double
    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 the
    document so to print fail you need:

    print $rss->status;
    

See it

As a tip you can always dump the content of the XML object by doing print_r($rss);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文