获得SimpleXMLElement中以'@'为前缀的值

时间:2013-05-07 21:58:27

标签: php simplexml

我有这行代码:

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项目,为什么我不能得到它?

1 个答案:

答案 0 :(得分:0)

var_dump($item->figure->iframe->attributes());

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