PHP getName() Function

In this chapter you will learn:

  1. Description for PHP getName() Function
  2. Syntax for PHP getName() Function
  3. Return for PHP getName() Function
  4. 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:

  1. Description for PHP getNamespaces() Function
  2. Syntax for PHP getNamespaces() Function
  3. Parameter for PHP getNamespaces() Function
  4. Return for PHP getNamespaces() Function
  5. Example - Return the namespaces used in the XML document
Home » PHP Tutorial » PHP SimpleXML Functions
PHP SimpleXMLElement Create
PHP addAttribute() Function
PHP addChild() Function
PHP asXML() Function
PHP attributes() Function
PHP children() Function
PHP SimpleXML count() Function
PHP getDocNamespaces() Function
PHP getName() Function
PHP getNamespaces() Function
PHP registerXPathNamespace() Function
PHP simplexml_import_dom() Function
PHP simplexml_load_file() Function
PHP simplexml_load_string() Function
PHP xpath() Function