SimpleXMLElement::attributes

Identifies an element's attributes

&reftitle.description; public `SimpleXMLElement` `SimpleXMLElement::attributes` `string` `ns`&null; `bool` `is_prefix` false

This function provides the attributes and values defined within an xml tag.

&simplexml.iteration;
&reftitle.parameters;

`ns`

- An optional namespace for the retrieved attributes

`is_prefix`

- Default to &false;

&reftitle.returnvalues;

Returns a `SimpleXMLElement` object that can be iterated over to loop through the attributes on the tag.

Returns &null; if called on a `SimpleXMLElement` object that already represents an attribute and not a tag.

&reftitle.examples;

### Interpret an XML string

    <?php
    $string = <<<XML
    <a>
     <foo name="one" game="lonely">1</foo>
    </a>
    XML;

    $xml = simplexml_load_string($string);
    foreach($xml->foo[0]->attributes() as $a => $b) {
        echo $a,'="',$b,"\"\n";
    }
    ?>

&example.outputs;

    name="one"
    game="lonely"

&reftitle.seealso;

- simplexml.examples-basic