Atributos de PHP () Función
Ejemplo
Devuelve los atributos y valores para el elemento XML <body>:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2014-01-01" type="private">Do
not forget me this weekend!</body>
</note>
XML;
$xml = simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,"<br>";
}
?>
Definición y uso
La función atributos() devuelve los atributos y valores de un elemento XML.
Sintaxis
SimpleXMLElement::attributes(ns, prefix)
Valores paramétricos
Parameter | Description |
---|---|
ns | Optional. Specifies a namespace for the retrieved attributes |
prefix | Optional. Specifies TRUE if ns is a prefix and FALSE if ns is a URI. Default is FALSE |
Detalles técnicos
Valor devuelto: | Un objeto SimpleXMLElement en caso de éxito |
---|---|
Versión PHP: | 5.0+ |
❮ Referencia PHP SimpleXML