PHP- Attribute()- Funktion
Beispiel
Geben Sie die Attribute und Werte für das XML-<body>-Element zurück:
<?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>";
}
?>
Definition und Verwendung
Die Funktion attributes() gibt die Attribute und Werte eines XML-Elements zurück.
Syntax
SimpleXMLElement::attributes(ns, prefix)
Parameterwerte
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 |
Technische Details
Rückgabewert: | Bei Erfolg ein SimpleXMLElement-Objekt |
---|---|
PHP-Version: | 5.0+ |
❮ PHP-SimpleXML-Referenz