Fonctions attributes()de PHP
Manuel de référence PHP SimpleXML
Exemples
Retourne les attributs et les valeurs de l'élément body du XML :
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Rappel</heading>
<body date="2013-01-01" type="private">Ne m'oubliez pas ce week-end !</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,""<br>";
}
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Rappel</heading>
<body date="2013-01-01" type="private">Ne m'oubliez pas ce week-end !</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,""<br>";
}
?>
Exécuter l'exemple »
Définition et utilisation
La fonction attributes() retourne les attributs et les valeurs d'une balise XML.
Syntaxe
attributes(ns,is_prefix);
| Parameters | Description |
|---|---|
| ns | Facultatif. Spécifie l'espace de noms de l'attribut à récupérer. |
| is_prefix | Facultatif. Spécifie une valeur booléenne. Sinsest un préfixe, TRUE, sinsest un URI, FALSE. La valeur par défaut est FALSE. |
Détails techniques
| Valeur de retour : | Renvoie un objet SimpleXMLElement en cas de succès. |
|---|---|
| Version de PHP : | 5.0.1+ |
Manuel de référence SimpleXML PHP Autres extensions