PHP | DOMDocument importNode() Function Last Updated : 27 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The DOMDocument::importNode() function is an inbuilt function in PHP which is used to return a copy of the node which need to import and associates it with the current document. Syntax: DOMNode DOMDocument::importNode( DOMNode $importedNode, bool $deep = FALSE ) Parameters: This function accepts two parameters as mentioned above and described below: $importedNode: This parameter holds the node which need to import. $deep: This parameter holds the Boolean value. If it set to TRUE then it will recursively import the subtree under the importedNode. Return Value: This function returns the copied node on success or FALSE, if it cannot be copied. Below program illustrates the DOMDocument::importNode() function in PHP: Program: php <?php // Create a new document $dom = new DOMDocument; // Load the XML document $dom->loadXML("<root><contact><email>[email protected]</email> <mobile>+91-987654321</mobile></contact></root>"); // Use getElementsByTagName() function to search // all elements with given local tag name $node = $dom->getElementsByTagName("contact")->item(0); // Create a new document $dom1 = new DOMDocument; $dom1->formatOutput = true; // Load the XML document $dom1->loadXML("<root><contactinfo><email>[email protected]</email> <mobile>+91-987654321</mobile></contactinfo></root>"); echo "Document before copying the nodes\n"; // Save the file in XML and display it echo $dom1->saveXML(); // Use importNode() function to import the node $node = $dom1->importNode($node, true); // Append child to the document $dom1->documentElement->appendChild($node); echo "\nDocument after copying the nodes\n"; // Save XML document and display it echo $dom1->saveXML(); ?> Output: Document before copying the nodes <?xml version="1.0"?> <root> <contactinfo><email>[email protected]</email> <mobile>+91-987654321</mobile></contactinfo> </root> Document after copying the nodes <?xml version="1.0"?> <root> <contactinfo><email>[email protected]</email> <mobile>+91-987654321</mobile></contactinfo> <contact><email>[email protected]</email> <mobile>+91-987654321</mobile></contact> </root> Reference: https://www.php.net/manual/en/domdocument.importnode.php Comment More infoAdvertise with us Next Article PHP | DOMDocument importNode() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | DOMDocument load() Function The DOMDocument::load() function is an inbuilt function in PHP which is used to load an XML document from a file. Syntax: mixed DOMDocument::load( string $filename, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $filename: This parameter h 1 min read PHP | DOMDocument loadXML() Function The DOMDocument::loadXML() function is an inbuilt function in PHP which is used to load the XML file from a string. Syntax: mixed DOMDocument::loadXML( string $source, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $source: This parameter 2 min read PHP | DOMDocument loadHTML() Function The DOMDocument::loadHTML() function is an inbuilt function in PHP which is used to load HTML file from a string. Syntax: bool DOMDocument::loadHTML( string $source, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $source: This parameter ho 2 min read PHP | DOMDocument loadHTMLFile() Function The DOMDocument::loadHTMLFile() function is an inbuilt function in PHP which is used to load HTML from a file. Syntax: bool DOMDocument::loadHTMLFile( string $filename, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $filename: This paramet 2 min read PHP | DOMNode isSameNode() Function The DOMNode::isSameNode() function is an inbuilt function in PHP which indicates if two nodes are the same node or not. Syntax: bool DOMNode::isSameNode( DOMNode $node ) Parameters: This function accepts a single parameter $node which holds the node to be compared. Return Value: This function return 2 min read Like