THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP attributes() Function

PHP SimpleXML Reference PHP SimpleXML Reference

Example

Return attributes and values within the XML <body> element:

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2014-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 attributes and values within an XML tag.


Syntax

attributes(ns,is_prefix);

Parameter Description
ns Optional. Specifies a namespace for the retrieved attributes
is_prefix Optional. Specifies a Boolean value. TRUE if ns is a prefix. FALSE if ns is a URI. Default is FALSE

Technical Details

Return Value: Returns a SimpleXMLElement object on success
PHP Version: 5.0.1+

PHP SimpleXML Reference PHP SimpleXML Reference