Sto tentando di modificare tutti i tag <P>
in un documento su <DIV>
. Questo è ciò che mi è venuta in mente, ma non sembra funzionare:PHP - DOMDocument - necessità di modificare/sostituire un tag HTML esistente con uno nuovo
$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);
}
Questo è il risultato che voglio:
Prima:
<p>Some text here</p>
Dopo:
<div>Some text here</div>
Questo funziona http://stackoverflow.com/a/21885789/175071 –