PHP attributes() Function

Description

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

Syntax

PHP attributes() Function has the following syntax.

attributes(ns,is_prefix);

Parameter

ParameterIs RequiredDescription
nsOptional.A namespace for the retrieved attributes
is_prefixOptional.A Boolean value. TRUE if ns is a prefix. FALSE if ns is a URI. Default is FALSE

Return

Returns a SimpleXMLElement object on success.

Example

Return attributes and values within the XML body element:


<?php/*from  w  w  w .  j  a  va 2s  . com*/
$note=<<<XML
<book>
    <name date="2013-01-01" type="public">PHP</name>
    <name date="2013-01-01" type="private">Java</name>
</book>
XML;


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




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions