use FastD\Dom\Document; $doc = new Document(); $doc->formatOutput = true; $title = $doc->createElement('title'); $title->nodeValue = 'My Web Page'; $body = $doc->createElement('body'); $body->nodeValue = 'Hello, world!'; $doc->appendChild($title); $doc->appendChild($body); echo $doc->saveHTML();
use FastD\Dom\Document; $doc = new Document(); $doc->loadHTMLFile('index.html'); $newEl = $doc->createElement('div'); $newEl->setAttribute('class', 'my-class'); $newEl->nodeValue = 'Some new content'; $body = $doc->getElementsByTagName('body')->item(0); $body->appendChild($newEl); $doc->saveHTMLFile('index.html');In this example, we load an existing HTML document called "index.html" using the `loadHTMLFile` method. Then we create a new `div` element, set its class to "my-class", and set its content to "Some new content". We retrieve the `body` element of the document and append the new element to it. Finally, we save the modified HTML back to the same file. Overall, PHP FD View provides an easy-to-use interface for working with HTML documents in PHP. This package library can be installed using Composer.