Current Location: Home> Function Categories> attributes

attributes

Returns the attribute/value of the element.
Name:attributes
Category:Uncategorized
Programming Language:php
One-line Description:Returns the attribute/value of the element.

Definition and usage

attributes() function returns the attributes and values ​​of an XML element.

实例

返回 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>";
  }
?>

运行实例

grammar

 SimpleXMLElement :: attributes ( ns , prefix )
parameter describe
ns Optional. Specifies the namespace for the retrieved attribute.
prefix Optional. TRUE is specified if ns is a prefix; if ns is a URI, FALSE is specified. The default is FALSE.
Similar Functions
Popular Articles