Atrybuty PHP () Funkcja
Przykład
Zwróć atrybuty i wartości elementu 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>";
}
?>
Definicja i użycie
Funkcja attribute() zwraca atrybuty i wartości elementu XML.
Składnia
SimpleXMLElement::attributes(ns, prefix)
Wartości parametrów
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 |
Szczegóły techniczne
Wartość zwrotu: | Obiekt SimpleXMLElement po sukcesie |
---|---|
Wersja PHP: | 5.0+ |
❮ Dokumentacja PHP SimpleXML