PHP | DOMDocument createElement() Function Last Updated : 27 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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: $name: This parameter holds the tag name of the element. $value: This parameter holds the value of the element. The default value of this function creates an empty element. The value of element can be set later using DOMElement::$nodeValue. Return Value: This function returns a new instance of class DOMElement on success or FALSE on failure. Below programs illustrate the DOMDocument::createElement() function in PHP: Program 1: php <?php // Create a new DOMDocument $domDocument = new DOMDocument('1.0', 'iso-8859-1'); // Use createElement() function to add a new element node $domElement = $domDocument->createElement('organization', 'GeeksforGeeks'); // Append element to the document $domDocument->appendChild($domElement); // Save XML file and display it echo $domDocument->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <organization>GeeksforGeeks</organization> Program 2: php <?php // Create a new DOMDocument $domDocument = new DOMDocument('1.0', 'iso-8859-1'); // 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($domElement1); $domElement1->appendChild($domElement2); $domElement1->appendChild($domElement3); $domElement1->appendChild($domElement4); // Save XML file and display it echo $domDocument->saveXML(); ?> Output: <?xml version="1.0" encoding="iso-8859-1"?> <organization> <name>GeeksforGeeks</name> <address>Noida</address> <email>[email protected]</email> </organization> Reference: https://www.php.net/manual/en/domdocument.createelement.php Comment More infoAdvertise with us Next Article PHP | DOMDocument createElement() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads 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 createComment() Function 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. R 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 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 createEntityReference() Function The DOMDocument::createEntityReference() function is an inbuilt function in PHP which is used to create a new instance of class DOMEntityReference. Syntax: DOMEntityReference DOMDocument::createEntityReference( string $name ) Parameters: This function accepts single parameter $name which holds the c 1 min read Like