SimpleXMLElement::attributes

(PHP 5, PHP 7)

SimpleXMLElement::attributesIdentifies an element's attributes

说锟斤拷

public SimpleXMLElement::attributes ([ string $ns = NULL [, bool $is_prefix = FALSE ]] ) : SimpleXMLElement

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

Note: SimpleXML 锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟接碉拷锟斤拷锟斤拷锟皆的癸拷锟津。诧拷锟斤拷通锟斤拷使锟斤拷 var_dump() 锟斤拷锟轿何可硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷榭达拷锟�

锟斤拷锟斤拷

ns

An optional namespace for the retrieved attributes

is_prefix

Default to FALSE

锟斤拷锟斤拷值

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.

锟斤拷锟斤拷

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";
}
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

name="one"
game="lonely"

锟轿硷拷