Created
April 13, 2021 15:46
-
-
Save delboy1978uk/0ba9ed1562c9bd8465dcc6828997c88e to your computer and use it in GitHub Desktop.
DOM Document appending fragments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dom = new DOMDocument(); | |
$html = '<head><meta garbage="what"/></head>'; | |
$head = $dom->createDocumentFragment(); | |
$head->appendXML($html); | |
$html = '<body><h1>Hello</h1></body>'; | |
$body = $dom->createDocumentFragment(); | |
$body->appendXML($html); | |
$html = '<p>Paragraph</p>'; | |
$paragraph = $dom->createDocumentFragment(); | |
$paragraph->appendXML($html); | |
$html = '<hl /><p>Footer</p>'; | |
$footer = $dom->createDocumentFragment(); | |
$footer->appendXML($html); | |
$body->appendChild($paragraph); | |
$dom->appendChild($head); | |
$dom->appendChild($body); | |
$dom->appendChild($footer); | |
echo $dom->saveHTML(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment