PHP getName() Function
In this chapter you will learn:
- Description for PHP getName() Function
- Syntax for PHP getName() Function
- Return for PHP getName() Function
- Example - Return the name of the XML element and the children
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//j av 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.
Next chapter...
What you will learn in the next chapter:
- Description for PHP getNamespaces() Function
- Syntax for PHP getNamespaces() Function
- Parameter for PHP getNamespaces() Function
- Return for PHP getNamespaces() Function
- Example - Return the namespaces used in the XML document
Home » PHP Tutorial » PHP SimpleXML Functions