【问题标题】:Getting value that is prepended with '@' in SimpleXMLElement [duplicate]获取在 SimpleXMLElement 中以“@”开头的值 [重复]
【发布时间】:2013-05-07 21:58:26
【问题描述】:

我有这行代码:

print_r($item->figure->iframe);

产生这个输出:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [height] => 288
            [mozallowfullscreen] => true
            [src] => http://www.hulu.com/embed.html?eid=Bq_uuy5X4KWFpYZgwa9e9g
            [allowfullscreen] => true
            [width] => 512
            [frameborder] => 0
            [scrolling] => 0
            [webkitAllowFullScreen] => true
        )

)

然后我试试这个:

var_dump($item->figure->iframe->{'@attributes'}["src"]);

然后给我这个:

NULL

我做错了什么?我想得到src的物品,为什么我得不到?

【问题讨论】:

  • 不先阅读文档就使用SimpleXMLElement类也是错误的。
  • 还有see here

标签: php simplexml


【解决方案1】:
var_dump($item->figure->iframe->attributes());

http://php.net/manual/en/simplexmlelement.attributes.php

【讨论】:

    猜你喜欢
    • 2014-09-03
    • 1970-01-01
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 2017-03-30
    相关资源
    最近更新 更多