PHP DOMDocument saveHTML () function

PHP

Syntax:
string DOMDocument::saveHTML (DOMNode $node = NULL)
Parameters:This function takes one parameter, $node,which is optional and is used to display a subset of the document.Return value: this function returns an HTML document on success or FALSE on error.The following program illustrates the DOMDocument::saveHTML() function in PHP:Program:  
// Create a new DOMDocument $domDocument = new DOMDocument ( '1.0' );  
// Create root element $root = $domDocument -> createElement ( 'html' );  
// Add an element to the document as the root element $root = $domDocument -> appendChild ( $root );  
// Create the head element $head = $domDocument -> createElement ( 'head' );  
// Add an element to the document
// as a child $head = $root -> appendChild ( $head );  
// Create header element $title = $domDocument -> createElement ( 'title' );  
// Add an element to the document
// as a child $title = $head -> appendChild ( $title );  
// Create text node $text = $domDocument -> createTextNode ( 'DOMDocument::saveHTML() function' );  
// Add a text node to the title element $text = $title -> appendChild ( $text );  
// Create body element $body = $domDocument -> createElement ( 'body' );  
// Add an element to the document
// as a child $body = $root -> appendChild ( $body );  
// Create header element $h1 = $domDocument -> createElement ( 'h1' );  
// Add an element to the document $h1 = $body -> appendChild ( $h1 );  
// Create text node $text = $domDocument -> createTextNode ( 'GeeksforGeeks' );  
// Add a text node to the header element $text = $h1 -> appendChild ( $text );  
// Create header element $h2 = $domDocument -> createElement ( 'h2' );  
// Add an element to the document $h2 = $body -> appendChild ( $h2 );  
// Create text node $text = $domDocument -> createTextNode ( 'DOMDocument::saveHTML() function' );  
// Add a text node to the header element $text = $h2 -> appendChild ( $text );  
// Use saveHTML() function to create
// HTML document echo $domDocument -> saveHTML();  
?>
Output:
  < title > DOMDocument::saveHTML() function < / title > < / head > < body > 

GeeksforGeeks < / h1 > 


DOMDocument::saveHTML() function < / h2> < / body > < / html >

Link: https:// www .php.net / manual / en / domdocument.savehtml.php