Create a new DOMComment object in PHP

Description

The following code shows how to create a new DOMComment object.

Example


//from  ww  w .  j a  v a  2  s .  c o  m
<?php

$dom = new DOMDocument('1.0', 'iso-8859-1');
$element = $dom->appendChild(new DOMElement('root'));
$comment = $element->appendChild(new DOMComment('root comment'));
echo $dom->saveXML(); 
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    XML »




DOM
SimpleXML
SimpleXMLElement
XML Parser