I\'m trying to change all tags in a document to
You are appending the div
to your p
which results in
p
will remove everything.$divnode->createElement()
won't work when $divnode
isn't initialized.
Try instead to use the DOMDocument::replaceChild() (the div
s position in the dom will be the same as the p
s).
foreach( $dom->getElementsByTagName("p") as $pnode ) {
$divnode = $dom->createElement("div", $pnode->nodeValue);
$dom->replaceChild($divnode, $pnode);
}