PHP children() Function

In this chapter you will learn:

  1. Description for PHP children() Function
  2. Syntax for PHP children() Function
  3. Parameter for PHP children() Function
  4. Return for PHP children() Function
  5. Example - Find the children of the note node

Description

The children() function finds the children of a specified node.

Syntax

PHP children() Function has the following syntax.

children(ns,is_prefix);

Parameter

ParameterIs requiredDescription
nsOptional.An XML namespace
is_prefixOptional.If TRUE, ns is regarded as a prefix. If FALSE, ns is regarded as a namespace URL

Return

Returns a SimpleXMLElement object

Example

Find the children of the note node:


<?php/*ja v a 2  s. c  o m*/
$note=<<<XML
<book>
    <name>PHP</name>
    <name>Java</name>
</book>
XML;

$xml=simplexml_load_string($note);
foreach ($xml->children() as $child){
  echo "Child node: " . $child . "\n";
}
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Description for PHP count() Function
  2. Syntax for PHP count() Function
  3. Return for PHP count() Function
  4. Example - Count the children of the book nodes
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