Home > Article > Backend Development > How to use php attributes function
php attributes function is used to return the attributes and values of XML tags. Its syntax is attributes(ns,is_prefix). The parameter ns is optional and specifies the namespace of the retrieved attributes; is_prefix is optional and specifies a Boolean value.
#How to use the php attributes function?
Definition and Usage
The attributes() function returns the attributes and values of the XML tag.
Syntax
attributes(ns,is_prefix);
Parameters
ns Optional. Specifies the namespace of the properties to be retrieved.
is_prefix Optional. Specifies a boolean value. TRUE if ns is a prefix, FALSE if ns is a URI. Default is FALSE.
Return value: If successful, a SimpleXMLElement object is returned.
PHP Version: 5.0.1
Example
Return the attributes and values of 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>"; } ?>
The above is the detailed content of How to use php attributes function. For more information, please follow other related articles on the PHP Chinese website!