PHP | DOMNode normalize() Function Last Updated : 02 Mar, 2020 Comments Improve Suggest changes Like Article Like Report The DOMNode::normalize() function is an inbuilt function in PHP which is used to remove empty text nodes and merge adjacent text nodes in this node and all its children. Syntax: void DOMNode::normalize( void ) Parameters: This function doesn’t accept any parameters. Return Value: This function does not return any value. Below examples illustrate the DOMNode::normalize() function in PHP: Example 1: In this program, we will show how normalize removes empty text nodes. php <?php // Create a new DOMDocument instance $document = new DOMDocument(); // Create a div element $element = $document-> appendChild(new DOMElement('div')); // Create a text Node $text1 = $document-> createTextNode('GeeksforGeeks'); // Create a empty text Node $text2 = $document->createTextNode(''); // Create another empty text Node $text3 = $document->createTextNode(''); // Append the nodes $element->appendChild($text1); $element->appendChild($text2); $element->appendChild($text3); echo "Number of text nodes before normalization: "; echo count($element->childNodes) . "<br>"; // Normalize the document $document->normalize(); echo "Number of text nodes after normalization: "; echo count($element->childNodes); ?> Output: Number of text nodes before normalization: 3 Number of text nodes after normalization: 1 Example 2: In this program, we will show how normalize merges all neighbor text nodes. php <?php // Create a new DOMDocument instance $document = new DOMDocument(); // Create a div element $element = $document-> appendChild(new DOMElement('div')); // Create a text Node $text1 = $document-> createTextNode('Hello'); // Create another text Node $text2 = $document-> createTextNode('World'); // Append the nodes $element->appendChild($text1); $element->appendChild($text2); echo "Number of text nodes " . "before normalization: "; echo count($element->childNodes) . "<br>"; // Normalize the document $document->normalize(); echo "Number of text nodes after " . "normalization: "; echo count($element->childNodes); ?> Output: Number of text nodes before normalization: 2 Number of text nodes after normalization: 1 Reference: https://www.php.net/manual/en/domnode.normalize.php Comment More infoAdvertise with us Next Article PHP | DOMNode normalize() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads 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 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 PHP | DOMNode insertBefore() Function The DOMNode::insertBefore() function is an inbuilt function in PHP which is used to insert a new node before a certain another node. Syntax: DOMNode DOMNode::insertBefore( DOMNode $newNode, DOMNode $refNode ) Parameters:This function accepts two parameters as mentioned above and described below: $ne 2 min read PHP | DOMDocument normalizeDocument() Function The DOMDocument::normalizeDocument() function is an inbuilt function in PHP which is used to normalize the document. This function is used to convert the document into the normal form if you saved and then loaded the document. Syntax: void DOMDocument::normalizeDocument( void ) Parameters: This func 1 min read PHP | DOMNode lookupPrefix() Function The DOMNode::lookupPrefix() function is an inbuilt function in PHP which is used to get the namespace prefix of the node based on the namespace URI.Syntax:  string DOMNode::lookupPrefix( string $namespaceURI ) Parameters: This function accepts a single parameter $namespaceURI which holds the namesp 1 min read Like