PHP attributes() Funktion
Definition und Verwendung
Die attributes() Funktion holt die Attribute des SimpleXML-Elements.
Diese Funktion bietet die Attribute und Werte an, die in einem XML-Tag definiert sind.
Syntax
class SimpleXMLElement { string attributes(ns,is_prefix) }
Parameter | Beschreibung |
---|---|
ns | Optional. Der Namensraum des gesuchten Attributs. |
is_prefix | Optional. Standard ist false. |
Beispiel
XML-Datei:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Erinnerung</heading> <body type="small" important="low">Vergiss das Treffen nicht!</body> </note>
PHP-Code:
<?php $xml = simplexml_load_file("test.xml"); foreach($xml->body[0]->attributes() as $a => $b) { echo $a,'="',$b,'"'; } ?>
Ausgabe:
type="small" important="low"