html - PHP DOMDocument - ignore unexpected closing tags -


i'm kind of hacking wordpress theme footer, , found little problem.

what doing taking footer of parent theme, capturing output, , using domdocument modify element. here code:

<?php // apologize in advance messy code....  /** * javascript-like html dom element * * class extends php's domelement allow * users , set innerhtml property of lalalalala.... * * @author keyvan minoukadeh - http://www.keyvan.net - keyvan@keyvan.net * @see http://fivefilters.org (the project written for) */ // blahblahblah  ob_start(); require get_theme_root() . '/responsive/footer.php'; $output = ob_get_clean();  libxml_use_internal_errors(true);  $dom = new domdocument(); $dom->registernodeclass('domelement', 'jslikehtmlelement'); $dom->loadhtml($output); $finder = new domxpath($dom); $classname="powered"; $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]"); $elem = $nodes->item(0);  $elem->innerhtml = "hahaha..gotcha!";  echo $dom->savehtml(); ?> 

however, footer output contains 2 </div>s (unexpected closing tags) , making domdocument complain. in fact, gets rid of </div>s , makes page weird. can't add </div></div> beginning of output because there stuffing around </div>s.

is there way domdocument ignore unexpected tags , leave them there or should use different library?

i found solution!

instead of using php's domdocument, used simple html dom library. doesn't complain errors, , reduces amount of code!

<?php // simple html dom parser require (get_stylesheet_directory() . '/core/includes/simple_html_dom.php');  ob_start(); require (get_theme_root() . '/responsive/footer.php'); $outputhtml = str_get_html(ob_get_clean());  $outputhtml->find("div.powered", 0)->innertext = "<a href='/privacy-policy'>privacy</a>";  echo $outputhtml; ?> 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)