PHP getName() Function

❮ PHP SimpleXML Reference

Example

Return the name of the XML element and the children:

<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars>
  <car id="1">Volvo</car>
  <car id="2">BMW</car>
  <car id="3">Saab</car>
</cars>
XML;

$sxe=new SimpleXMLElement($xml);
// Get the name of the cars element
echo $sxe->getName() . "<br>";

// Also print out the names of the children of the cars element
foreach ($sxe->children() as $child)
  {
  echo $child->getName() . "<br>";
  }
?>
Run Example »

Definition and Usage

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


Syntax

SimpleXMLElement::getName()

Technical Details

Return Value: The name of the XML element, as a string
PHP Version: 5.1.3+

❮ PHP SimpleXML Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.