I'm trying to use masterminds/html5-php in order to manipulate some html5 documents. I don't know whether the document is a full HTML page or some part of html code so I'm trying to manipulate it like this.
$html5 = new HTML5();
$dom = $html5->loadHTML($html);
if($html5->hasErrors())
return $html;
$domObject = new Zend_Dom_Query();
$domObject->setDocument($dom);
if (empty($selector))
return $html;
$domElements = $domObject->query($selector);
if ($domElements->count() > 0) {
foreach ($domElements as $domElement) {
$domElement->parentNode->removeChild($domElement);
}
}
$result = $html5->saveHTML($dom);
return $result;
My problem is that saveHTML() will wrap the html code in so my final document ends up being full of tags all over the place.
Is there a way to alter this behaviour? Perhaps by overriding the saveHTML method? Any hints are appreciated.
here is the original HTML
<div class="language-currency-wrapper ">
<div class="language-currency-block">
<span class="language">
<img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/English.jpg" alt="English" />
<span class="io-language-label hidden-xs">English</span>
</span>
<i class="icon-down-open-mini"></i>
</div>
<div class="language-currency-dropdown">
<div class="form-language list">
<div class="label">Your Language:</div>
<a href="http://domain.gr/products/bmw/f32.html?___store=en&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/English.jpg" alt="English" /><span class="hidden-xs">English</span></a>
<a href="http://domain.gr/products/bmw/f32.html?___store=de&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/German.jpg" alt="German" /><span class="hidden-xs">German</span></a>
<a href="http://domain.gr/products/bmw/f32.html?___store=el&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/Greek.jpg" alt="Greek" /><span class="hidden-xs">Greek</span></a>
</div>
</div>
<div class="clearfix"></div>
</div>
Here is what saveHTML produces
<!DOCTYPE html>
<html><div class="language-currency-wrapper ">
<div class="language-currency-dropdown">
<div class="form-language list">
<div class="label">Your Language:</div>
<a href="http://domain.gr/products/bmw/f32.html?___store=en&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/English.jpg" alt="English"><span class="hidden-xs">English</span></a>
<a href="http://domain.gr/products/bmw/f32.html?___store=de&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/German.jpg" alt="German"><span class="hidden-xs">German</span></a>
<a href="http://domain.gr/products/bmw/f32.html?___store=el&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/Greek.jpg" alt="Greek"><span class="hidden-xs">Greek</span></a>
</div>
</div>
<div class="clearfix"></div>
</div>
</html>
Here is what I was expecting
<div class="language-currency-wrapper ">
<div class="language-currency-dropdown">
<div class="form-language list">
<div class="label">Your Language:</div>
<a href="http://domain.gr/products/bmw/f32.html?___store=en&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/English.jpg" alt="English"><span class="hidden-xs">English</span></a>
<a href="http://domain.gr/products/bmw/f32.html?___store=de&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/German.jpg" alt="German"><span class="hidden-xs">German</span></a>
<a href="http://domain.gr/products/bmw/f32.html?___store=el&___from_store=en"><img src="http://domain.gr/skin/frontend/be/ioweb/images/lang/Greek.jpg" alt="Greek"><span class="hidden-xs">Greek</span></a>
</div>
</div>
<div class="clearfix"></div>
</div>
For simplicity I'm removing the language block