PHP getName() Function

Description

The getName() function returns the name of the XML element.

Syntax

PHP getName() Function has the following syntax.

getName();

Return

Returns the name of the XML tag referenced by the SimpleXMLElement object, as a string

Example

Return the name of the XML element and the children:


<?php//www. ja  v  a  2s . c o m
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<books>
  <book id="1">Java</book>
  <book id="2">PHP</book>
  <book id="3">CSS</book> 
</books>
XML;

$sxe=new SimpleXMLElement($xml);
echo $sxe->getName() . "\n";
foreach ($sxe->children() as $child){
   echo $child->getName() . "\n";
}
?>

The code above generates the following result.





















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