(PHP 5 >= 5.0.1)
SimpleXMLElement->attributes() — Identifies an element's attributes
This function provides the attributes and values defined within an xml tag.
Note: SimpleXML 創建了一條給大部分方法增加交互式屬性的規則。這些屬性不能夠使用 var_dump() 或其它檢查對象的方法來查看。
An optional namespace for the retrieved attributes
Default to FALSE
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";
}
?>
上例將輸出:
name="one" game="lonely"