Forum und email

SimpleXMLElement->attributes()

(PHP 5 >= 5.0.1)

SimpleXMLElement->attributes() — Identifies an element's attributes

Beskrivelse

SimpleXMLElement
SimpleXMLElement attributes ([ string $ns [, bool $is_prefix ]] )

This function provides the attributes and values defined within an xml tag.

Note: SimpleXML har gjort det til en regel at tilføje interaktive egenskaber på de fleste metoder. De kan ikke ses ved at bruge var_dump() eller andet der kan undersøge objekter.

Parameterliste

ns

An optional namespace for the retrieved attributes

is_prefix

Default to FALSE

Returneringsværdier

Eksempler

Example#1 Interpret an XML string

<?php
$string 
= <<<XML
<a xmlns:b>
 <foo name="one" game="lonely">1</foo>
</a>
XML;

$xml simplexml_load_string($string);
foreach(
$xml->foo[0]->attributes() as $a => $b) {
    echo 
$a,'="',$b,"\"\n";
}
?>

Ovenstående eksempel vil udskrive:

name="one"
game="lonely"