X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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="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 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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook