Given this markup
<badtag>
This is the title and <em>really</em> needs help
<badtag>
I need to remove the wrapper, but do it without losing the tag, which is what happens if I simply do something like:
dom->createTextNode(currentNode->nodeValue)
I've tried the following, but it's not quite working and I want to make sure I'm on the right track and not missing an easier way. I do note that I need to add iteration when I hit a tag in the switch statement (rather than #text) so that I get the contents of the tag (such as with the tag).
$l = $origElement->childNodes->length;
$new = [];
for ($i = 0; $i < $l; ++$i) {
$child = $origElement->childNodes->item($i);
switch ($child->nodeName) {
case '#text':
$new[] = $dom->createTextNode($origElement->textContent);
break;
default:
$new[] = $child;
break;
}
}
foreach ($new as $struct) {
$parentNode->insertBefore($struct, $origElement);
}
$origElement->parentNode->removeChild($origElement);