loadHTMLFile('index.html'); // save HTML back to file $doc->saveHTMLFile('new_index.html'); ?>
createElement('html'); $doc->appendChild($html); // create new head and body elements and append to html element $head = $doc->createElement('head'); $body = $doc->createElement('body'); $html->appendChild($head); $html->appendChild($body); // create new title element and append to head element $title = $doc->createElement('title', 'My Page'); $head->appendChild($title); // create new h1 element and append to body element $h1 = $doc->createElement('h1', 'Welcome to my page!'); $body->appendChild($h1); // save HTML to file $doc->saveHTMLFile('new_page.html'); ?>This example creates a new DOMDocument object and generates an HTML document with a title and header. It also adds a body element with an h1 title, then saves the HTML to a new file "new_page.html". The package library for the DOMDocument saveHTMLFile function is the core PHP library.