// Load the HTML file $html = file_get_contents('example.html'); // Create DOMDocument object $doc = new DOMDocument(); // Load the HTML into the DOMDocument $doc->loadHTML($html); // Update the HTML document // Save the updated HTML to the file $doc->saveHTMLFile('updated.html');
// Load the HTML file $html = file_get_contents('example.html'); // Create DOMDocument object $doc = new DOMDocument(); // Load the HTML into the DOMDocument $doc->loadHTML($html); // Update the HTML document // Save the HTML to a string $updated_html = $doc->saveHTML();In this example, we load an HTML file, create a DOMDocument object, and load the HTML into it. After performing some modifications on the HTML document, we save the updated HTML to a string using the DOMDocument saveHTML function. Package library: PHP DOM extension.