Accessing @attribute from SimpleXML

前端 未结 8 1259
后悔当初
后悔当初 2020-11-22 00:33

I am having a problem accessing the @attribute section of my SimpleXML object. When I var_dump the entire object, I get the correct output, and wh

8条回答
  •  隐瞒了意图╮
    2020-11-22 01:27

    $xml = <<
    
    
    XML;
    
    $sxml = simplexml_load_string($xml);
    $attrs = $sxml->elem->attributes();
    echo $attrs["attrib"]; //or just $sxml->elem["attrib"]
    

    Use SimpleXMLElement::attributes.

    Truth is, the SimpleXMLElement get_properties handler lies big time. There's no property named "@attributes", so you can't do $sxml->elem->{"@attributes"}["attrib"].

提交回复
热议问题