I am trying to change all the <P> tags in a document to <DIV> . This is what I came up with, but it doesn't seem to work:
$dom = new DOMDocument; $dom->loadHTML($htmlfile_data); foreach( $dom->getElementsByTagName("p") as $pnode ) { $divnode->createElement("div"); $divnode->nodeValue = $pnode->nodeValue; $pnode->appendChild($divnode); $pnode->parentNode->removeChild($pnode); }
This is the result I want:
Before:
<p>Some text here</p>
After:
<div>Some text here</div>
James nine
source share