How to access element attributes with SimpleXml? [

2019-01-12 08:05发布

问题:

This question already has an answer here:

  • Accessing @attribute from SimpleXML 8 answers

How can i, in php access the attributes values:

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

I have tried the following:

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

and many variations of this

回答1:

Just

echo $photos['total'];

See Example #5 Using attributes



标签: php simplexml