Change language

PHP DOMDocument saveHTMLFile () function

Syntax:
int DOMDocument::saveHTMLFile (string $filename)
Parameters:This function takes one parameter, $filename,which contains the path to save the HTML document.Return value:this function returns the number of bytes on success or FALSE on error.The following program illustrates the DOMDocument::saveHTMLFile() function in PHP:Program:  
// Create a new DOMDocument $domDocument = new DOMDocument ( ’1.0’ );  
// Create root element $root = $domDocument -> createElement ( ’html’ );  
// Add element to document as 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 element to 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 saveHTMLFile() to save
// HTML document $domDocument -> saveHTMLFile ( ’gfg.html’ ); echo " HTML file saved successfully " ;  
?>
Output:
HTML file saved successfully
Content of the saved HTML file gfg.html: < html > < head > < meta http-equiv = "Content-Type" content = "text / html; charset = UTF-8" > < title > DOMDocument::saveHTML() function < / title > < / head > < body > < h1 > GeeksforGeeks < / h1 > < h2 > DOMDocument::saveHTML() function < / h2 > < / body > < / html > Link: https://www.php.net/manual/en/domdocument.savehtmlfile.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method