SimpleXMLElement::attributes

(PHP 5, PHP 7)

SimpleXMLElement::attributesIdentifies an element's attributes

Descrierea

public SimpleXMLElement::attributes ( string $ns = null , bool $is_prefix = false ) : SimpleXMLElement

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

Notă: SimpleXML a creat o regulă de a adăuga proprietăți iterative la majoritatea metodelor. Ele nu pot fi vizualizate cu ajutorul var_dump() sau orice altceva ce poate examina obiecte.

Parametri

ns

An optional namespace for the retrieved attributes

is_prefix

Default to false

Valorile întoarse

Returns a SimpleXMLElement object that can be iterated over to loop through the attributes on the tag.

Returns null if called on a SimpleXMLElement object that already represents an attribute and not a tag.

Istoricul schimbărilor

Versiune Descriere
5.2.0 The optional parameter is_prefix was added.

Exemple

Example #1 Interpret an XML string

<?php
$string 
= <<<XML
<a>
 <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";
}
?>

Exemplul de mai sus va afișa:

name="one"
game="lonely"

A se vedea și