Fonction PHP attributs()
Exemple
Renvoyez les attributs et les valeurs de l'élément 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>";
}
?>
Définition et utilisation
La fonction attributs() renvoie les attributs et les valeurs d'un élément XML.
Syntaxe
SimpleXMLElement::attributes(ns, prefix)
Valeurs des paramètres
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 |
Détails techniques
Valeur de retour : | Un objet SimpleXMLElement en cas de succès |
---|---|
Version PHP : | 5.0+ |
❮ Référence PHP SimpleXML