PHP | DOMNode cloneNode() function Last Updated : 25 Feb, 2020 Comments Improve Suggest changes Like Article Like Report The DOMNode::cloneNode() function is an inbuilt function in PHP which is used to create a copy of the node. Syntax: DOMNode DOMNode::cloneNode( bool $deep ) Parameters:This function accepts a single parameter $deep which indicates whether to copy all descendant nodes. This parameter is set to FALSE by default. Return Value: This function returns the cloned node. Program 1: php <?php // Create a DOMDocument $doc = new DOMDocument(); // Load XML $doc->loadXML('<html></html>'); // Create an heading element on DOMDocument object $h1 = $doc->createElement('h1', "geeksforgeeks"); // Append the child $doc->documentElement->appendChild($h1); // Create a new DOMDocument $doc_new = new DOMDocument(); // Deep clone the node to new instance $doc_new = $doc->cloneNode(true); // Render the cloned instance echo $doc_new->saveXML(); ?> Output: Program 2: php <?php // Create a DOMDocument $doc = new DOMDocument('1.0', 'iso-8859-1'); // Load XML $doc->loadXML('<html></html>'); // Create an heading element on DOMDocument object $h1 = $doc->createElement('h1', "geeksforgeeks"); // Append the child $doc->documentElement->appendChild($h1); // Shallow clone the node to a new instance // It will clone only the instance not its // children nodes $doc_new = $doc->cloneNode(false); // Render the cloned instance echo $doc_new->saveXML(); ?> Output: Press Ctrl + U to see the DOM Reference: https://www.php.net/manual/en/domnode.clonenode.php Comment More infoAdvertise with us Next Article PHP | DOMNode cloneNode() function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMNode C14N() Function The DOMNode::C14N() function is an inbuilt function in PHP which is used to convert a node into string. Syntax: string DOMNode::C14N( bool $exclusive, bool $with_comments, array $xpath, array $ns_prefixes ) Parameters: This function accepts four parameters as mentioned above and described below: $ex 2 min read PHP | DOMNode C14NFile() Function The DOMNode::C14NFile() function is an inbuilt function in PHP which is used to canonicalize nodes to a file. Syntax: int DOMNode::C14NFile( string $uri, bool $exclusive, bool $with_comments, array $xpath, array $ns_prefixes ) Parameters: This function accepts five parameters as mentioned above and 2 min read PHP | DOMNode appendChild() function The DOMNode::appendChild() function is an inbuilt function in PHP which is used to appends a child to an existing list of children or creates a new list of children. The child can be created with DOMDocument::createElement(), DOMDocument::createTextNode() or by using any other node. Syntax: DOMNode 2 min read PHP | DOMNamedNodeMap count() Function The DOMNamedNodeMap::count() function is an inbuilt function in PHP which is used to get the number of nodes in the map. It can be used to count attributes of a element. Syntax: int DOMNamedNodeMap::count( void ) Parameters: This function doesnât accepts any parameter. Return Value: This function re 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 Like