PHP | DOMNode C14N() Function Last Updated : 26 Feb, 2020 Comments Improve Suggest changes Like Article Like Report 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: $exclusive (Optional): It specifies whether to enable exclusive parsing of only the nodes matched by the provided xpath or namespace prefixes. $with_comments (Optional): It specifies whether to retain comments in output. $xpath (Optional): It specifies an array of xpaths to filter the nodes by. $ns_prefixes (Optional): It specifies an array of namespace prefixes to filter the nodes by. Return Value: This function returns canonicalized nodes as a string or FALSE on failure. Below examples illustrate the DOMNode::C14N() function in PHP: Example 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'); // Append the child $doc->documentElement->appendChild($h1); // Get the data without comments $stringdata = $doc->C14N(); echo $stringdata; ?> Output: <html><h1></h1></html> Example 2: php <?php // Create a DOMDocument $doc = new DOMDocument(); // Load XML $doc->loadXML('<html><!-- This is a comment --></html>'); // Create an heading element on DOMDocument object $h1 = $doc->createElement('h1'); // Append the child $doc->documentElement->appendChild($h1); // Get the data with comments $stringdata = $doc->C14N(false, true); echo 'With Comments: <br>'; echo htmlentities($stringdata); // Get the data without comments $stringdata = $doc->C14N(false, false); echo '<br>Without Comments: <br>'; echo htmlentities($stringdata); ?> Output: With Comments: <html><!-- This is a comment --><h1></h1></html>Without Comments: <html><h1></h1></html> Reference: https://www.php.net/manual/en/domnode.c14n.php Comment More infoAdvertise with us Next Article PHP | DOMNode C14N() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads 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 cloneNode() function 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 1 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 | 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 | DOMNode getLineNo() function The DOMNode::getLineNo() function is an inbuilt function in PHP which is used to get the line number for where the node is defined. Syntax: DOMNode DOMNode::getLineNo( void ) Parameters:This function doesnât accept any parameter. Return Value: This function returns the line number where the node was 2 min read Like