<?php
function merge_html($html) {
$dom = new DOMDocument;
$dom->loadHTML("<div id=\"tmptmptmp\">" . $html . "</div>", LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD);
$xp = new DOMXPath($dom);
$links = $xp->query('//div');
foreach ($links as $link) {
$class = $link->getAttribute('class');
$nested = $xp->query('.//div', $link);
foreach ($nested as $n) {
if ($n->getAttribute('class') == $class) {
//$html = $doc->getElementsByTagName("html")->item(0);
$fragment = $dom->createDocumentFragment();
while ($n->childNodes->length > 0) {
$fragment->appendChild($n->childNodes->item(0));
}
$n->parentNode->replaceChild($fragment, $n);
}
}
}
return preg_replace('/^\s*<div\s+id="tmptmptmp">\s*|\s*<\/div>\s*$/', '', $dom->saveHTML()); }
$html = '
<div class="dotted-highlight">
Here is a check list to determine whether you want this career or not.
<div class="dotted-highlight">
Tick all those apply to you. The more boxes you tick, the better suited you are to this career.
<ul>
<li>
You are hyper active and are always on your toes.
</li>
<li>
You are mentally and physically strong enough to withstand rigorous exercise.
</li>
</ul>
</div>
<div class="dotted-highlight">
You do not mind working in the early morning, late evenings, and on weekends and holidays.
</div>
</div>
<h2>
What work does it involve?
</h2><strong>To become a fitness instructor or a personal trainer, your main job is to help people with their exercise routines.</strong>
';
$html = merge_html($html);
?>