PHP 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。 |
技术细节
返回值: | 成功时返回 SimpleXMLElement 对象。 |
---|---|
PHP 版本: | 5.0+ |