Forum und email

SimpleXMLElement->attributes()

(PHP 5 >= 5.0.1)

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

說明

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

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

Return值

範例

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"