PHP SimpleXMLElement - getName() Method
The PHP SimpleXMLElement::getName() method gets the name of the XML element.
Syntax
public SimpleXMLElement::getName()
Parameters
No parameter is required.
Return Value
Returns the name of the XML tag referenced by the SimpleXMLElement object as a string.
Example:
The example below shows the usage of SimpleXMLElement::getName() method.
<?php $xmlstr = <<<XML <mail> <To>John Smith</To> <From>Marry G.</From> <Subject>Happy Birthday</Subject> <body>Happy birthday. Live your life with smiles.</body> </mail> XML; $xml = new SimpleXMLElement($xmlstr); echo $xml->getName() . "\n"; foreach ($xml->children() as $child) { echo $child->getName()."\n"; } ?>
The output of the above code will be:
mail To From Subject body
❮ PHP SimpleXML Reference