PHP属性()関数
例
XML <body>要素の属性と値を返します。
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2014-01-01" type="private">Do
not forget me this weekend!</body>
</note>
XML;
$xml = simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,"<br>";
}
?>
定義と使用法
attribute()関数は、XML要素の属性と値を返します。
構文
SimpleXMLElement::attributes(ns, prefix)
パラメータ値
Parameter | Description |
---|---|
ns | Optional. Specifies a namespace for the retrieved attributes |
prefix | Optional. Specifies TRUE if ns is a prefix and FALSE if ns is a URI. Default is FALSE |
技術的な詳細
戻り値: | 成功したSimpleXMLElementオブジェクト |
---|---|
PHPバージョン: | 5.0以降 |
❮PHPSimpleXMLリファレンス