loadHTMLFile('example.html'); $title = $doc->getElementsByTagName('title')->item(0)->nodeValue; echo $title; ?>
loadHTMLFile('example.html'); $body = $doc->getElementsByTagName('body')->item(0); $p = $doc->createElement('p', 'This is a new paragraph.'); $body->appendChild($p); echo $doc->saveHTML(); ?>Both examples use the DOMDocument class and the loadHTMLFile() method to load an HTML file. The first example uses the getElementsByTagName() method to extract the content of the title tag, while the second example uses createElement() and appendChild() methods to add a new paragraph to the body tag. The package library for the DOMDocument class is the PHP Standard Library.