This commit is contained in:
2019-02-11 17:36:40 +01:00
parent 14a732c31e
commit df674a7ec5
18 changed files with 344 additions and 62 deletions

31
test.php Normal file
View File

@ -0,0 +1,31 @@
<?php
ini_set('display_errors', 'On');
$doc = new DOMDocument();
$test = "<html><body><p>pouet</p></body></html>";
$doc->loadHTML($test);
appendHTML($doc->getElementsByTagName("body")->item(0), "<img src=\"./\">");
echo $doc->saveHTML();
function appendHTML(DOMNode $parent, $source) {
$tmpDoc = new DOMDocument();
$html = "<html><body>";
$html .= $source;
$html .= "</body></html>";
$tmpDoc->loadHTML('<?xml encoding="UTF-8">'.$html);
foreach ($tmpDoc->childNodes as $item)
if ($item->nodeType == XML_PI_NODE)
$tmpDoc->removeChild($item);
$tmpDoc->encoding = 'UTF-8';
foreach ($tmpDoc->getElementsByTagName('body')->item(0)->childNodes as $node) {
$importedNode = $parent->ownerDocument->importNode($node, true);
$parent->appendChild($importedNode);
}
}
?>