PHP attributes()Functions

PHP SimpleXML 参考手册PHP SimpleXML Reference Manual

Examples

Returns the attributes and values of the body element of the XML:

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2013-01-01" type="private">Don't forget me this weekend!</body>
</note>
XML;

$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,""<br>";
}
?>

Run Example »

Definition and Usage

The attributes() function returns the attributes and values of an XML tag.


Syntax

attributes(ns,is_prefix);

Parameters Description
ns Optional. Specifies the namespace of the attribute to retrieve.
is_prefix Optional. Specifies a boolean value. Ifnsit is a prefix, TRUE, ifnsit is a URI, FALSE. Default is FALSE.

Technical Details

Return value: Returns a SimpleXMLElement object if successful.
PHP Version: 5.0.1+


PHP SimpleXML 参考手册PHP SimpleXML Reference Manual Other Extensions