Open In App

PHP DOMDocument saveHTMLFile() Function

Last Updated : 03 Apr, 2023
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

The DOMDocument::saveHTMLFile() function is an inbuilt function in PHP that is used to create an HTML document from the DOM representation. This function is used after creating the dom document.

Syntax:

int DOMDocument::saveHTMLFile( string $filename )

Parameters: This function accepts a single parameter $filename which holds the path to save the HTML document.

Return Value: This function returns the number of bytes on success or FALSE on failure.

Below example illustrates the DOMDocument::saveHTMLFile() function in PHP:

Example:

Output:

HTML file saved successfully

The 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>

Reference: https://www.php.net/manual/en/domdocument.savehtmlfile.php


Similar Reads