PHP | DOMDocument createComment() Function Last Updated : 27 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The DOMDocument::createComment() function is an inbuilt function in PHP which is used to create a new instance of class createComment. Syntax: DOMComment DOMDocument::createComment( string $data ) Parameters: This function accepts single parameter $data which holds the content of the comment node. Return Value: This function returns the new DOMComment object on success or FALSE on failure. Below programs illustrate the DOMDocument::createComment() function in PHP: Program 1: php <?php // Create a new DOMDocument $domDocument = new DOMDocument('1.0', 'iso-8859-1'); // Use createComment() function to add a new comment node $domComment = $domDocument->createComment('GeeksforGeeks'); // Append element to the document $domDocument->appendChild($domComment); // Save the XML file and display it echo $domDocument->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <!--GeeksforGeeks--> Program 2: php <?php // Create a new DOMDocument $domDocument = new DOMDocument('1.0', 'iso-8859-1'); // Use createComment() function to add a new comment node $domComment1 = $domDocument->createComment('Starting XML document file'); $domComment2 = $domDocument->createComment('Ending XML document file'); // Use createElement() function to add a new element node $domElement1 = $domDocument->createElement('organization'); $domElement2 = $domDocument->createElement('name', 'GeeksforGeeks'); $domElement3 = $domDocument->createElement('address', 'Noida'); $domElement4 = $domDocument->createElement('email', '[email protected]'); // Append element to the document $domDocument->appendChild($domComment1); $domDocument->appendChild($domElement1); $domElement1->appendChild($domElement2); $domElement1->appendChild($domElement3); $domElement1->appendChild($domElement4); $domDocument->appendChild($domComment2); // Save the XML file and display it echo $domDocument->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <!--Starting XML document file--> <organization> <name>GeeksforGeeks</name> <address>Noida</address> <email>[email protected]</email> </organization> <!--Ending XML document file--> Reference: https://www.php.net/manual/en/domdocument.createcomment.php Comment More infoAdvertise with us Next Article PHP | DOMDocument createComment() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | DOMDocument createElement() Function The DOMDocument::createElement() function is an inbuilt function in PHP which is used to create a new instance of class DOMElement. Syntax: DOMElement DOMDocument::createElement( string $name, string $value ) Parameters: This function accepts two parameters as mentioned above and described below: $n 2 min read PHP DOMDocument createElementNS() Function The DOMDocument::createElementNS() function is an inbuilt function in PHP that is used to create a new element node with an associated namespace. Syntax: DOMElement DOMDocument::createElementNS( string $namespaceURI, string $qualifiedName, string $value ) Parameters: This function accepts three para 2 min read PHP | DOMDocument createDocumentFragment() Function The DOMDocument::createDocumentFragment() function is an inbuilt function in PHP which is used to create a new document fragment. Syntax: DOMDocumentFragment DOMDocument::createDocumentFragment( void ) Parameters: This function doesnât accepts any parameters. Return Value: This function returns a ne 2 min read PHP | DOMDocument createTextNode() Function The DOMDocument::createTextNode() function is an inbuilt function in PHP which is used to create a new instance of class DOMText. Syntax: DOMText DOMDocument::createTextNode( string $content ) Parameters: This function accepts single parameter $content which holds the content of the text. Return Val 1 min read PHP | DOMDocument createCDATASection() Function The DOMDocument::createCDATASection() function is an inbuilt function in PHP which is used to create a new instance of class DOMCDATASection. Syntax: DOMCDATASection DOMDocument::createCDATASection( string $data ) Parameters: This function accepts single parameter $data which holds the content of th 1 min read Like