attributes
返回元素的属性/值。
attributes()
函数返回 XML 元素的属性和值。
返回 XML <body> 元素的属性和值:
<?php $note=<<<XML <note> <to>George</to> <from>John</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>"; } ?>
运行实例
SimpleXMLElement::attributes(ns, prefix)
参数 | 描述 |
---|---|
ns | 可选。指定检索属性的命名空间。 |
prefix | 可选。如果 ns 是前缀,则指定 TRUE;如果 ns 是 URI,则指定 FALSE。默认为 FALSE。 |