当前位置: 首页> 函数类别大全> attributes

attributes

返回元素的属性/值。
名称:attributes
分类:未分类
所属语言:php
一句话介绍:返回元素的属性/值。

定义和用法

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。
同类函数
热门文章