PHP | DOMComment __construct() Function Last Updated : 14 Feb, 2020 Comments Improve Suggest changes Like Article Like Report The DOMComment::__construct() function is an inbuilt function in PHP which creates a new DOMComment object. This object is read only and can be appended to a document Syntax: public DOMComment::__construct( string $value) Parameters: This function accepts a single parameter $value which holds the comment. Below given programs illustrate the DOMComment::__construct() function in PHP: Program 1 (Simple comment): php <?php // Create a new DOM Document $dom = new DOMDocument('1.0', 'iso-8859-1'); // Create a h1 element $element = $dom->appendChild(new DOMElement('h1')); // Create a DOMComment $comment = $element->appendChild( new DOMComment('This line is a comment')); echo $dom->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <h1><!--This line is a comment--></h1> Program 2 (Using comments with elements): php <?php // Create a new DOM Document $dom = new DOMDocument('1.0', 'iso-8859-1'); // Create a h1 element $element = $dom->appendChild(new DOMElement('h1')); // Create a DOMCdataSection $comment = $element->appendChild(new DOMComment( 'This line is a comment about content')); // Create a div element $element = $element->appendChild(new DOMElement( 'div', 'This is the actual content')); echo $dom->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <h1><!--This line is a comment about content--> <div>This is the actual content</div></h1> Reference: https://www.php.net/manual/en/domcomment.construct.php Create Quiz Comment G gurrrung Follow 0 Improve G gurrrung Follow 0 Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like