如何使用SimpleXml访问元素属性? [英] How to access element attributes with SimpleXml?

查看:74
本文介绍了如何使用SimpleXml访问元素属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在php中访问属性值:

How can i, in php access the attributes values:

[photos] => SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [page] => 1
                [pages] => 1
                [perpage] => 24
                [total] => 18
            )

我尝试了以下操作:

$photos->@attributes['total'] ;
$photos->{'@attributes'}['total'] ;

及其许多变化

推荐答案

只是

echo $photos['total'];

请参见示例#5使用属性

这篇关于如何使用SimpleXml访问元素属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆