DOMNode_hasChildNodes_basic.phpt 856 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Test whether a node has child nodes: hasChildNodes()
  3. --SKIPIF--
  4. <?php
  5. include('skipif.inc');
  6. ?>
  7. --FILE--
  8. <?php
  9. /* Create an XML document
  10. * with strcuture
  11. * <book>
  12. * <title>This is the title</title>
  13. * </book>
  14. * Check for child nodes of the <book>, <title> and This is the title
  15. *
  16. */
  17. $doc = new DOMDocument();
  18. $root = $doc->createElement('book');
  19. $doc->appendChild($root);
  20. $title = $doc->createElement('title');
  21. $root->appendChild($title);
  22. $text = $doc->createTextNode('This is the title');
  23. $title->appendChild($text);
  24. echo "Root has child nodes: ";
  25. var_dump($root->hasChildNodes());
  26. echo "Title has child nodes: ";
  27. var_dump($title->hasChildNodes());
  28. echo "Text has child nodes: ";
  29. var_dump($text->hasChildNodes());
  30. ?>
  31. --EXPECTF--
  32. Root has child nodes: bool(true)
  33. Title has child nodes: bool(true)
  34. Text has child nodes: bool(false)