XML <body> 要素の属性と値を返します:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2014-01-01" type="private">Don't forget me this weekend!</body>
</note>
XML;
$xml = simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,"<br>";
}
?>
例の実行 »
attributes() 関数は、XMLタグの属性と値を返します。
attributes(ns,is_prefix);
パラメータ | 説明 |
---|---|
ns | 任意。取得する属性の名前空間を指定する |
is_prefix | 任意。ブール値を指定する。ns が接頭辞の場合は TRUE。ns が URI の場合は FALSE。デフォルトは FALSE |
返り値: | 成功した場合は SimpleXMLElement オブジェクトを返します |
---|---|
PHP バージョン: | 5.0.1+ |