PHP Tutorial - PHP getName() Function






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/*  w w  w .java  2 s. c  om*/
$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.