3

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

Gordon
  • 312,688
  • 75
  • 539
  • 559
mononym
  • 2,606
  • 6
  • 26
  • 27
  • Don't use `print_r()` on SimpleXMLElement. If you need to know what's inside, you use `->asXML()` on it. – Josh Davis Jan 07 '11 at 12:13
  • Related: [Accessing @attribute from SimpleXML](http://stackoverflow.com/questions/1652128/accessing-attribute-from-simplexml) – hakre Mar 05 '13 at 11:37

1 Answers1

8

Just

echo $photos['total'];

See Example #5 Using attributes

Gordon
  • 312,688
  • 75
  • 539
  • 559