php - removing the h3 closing tag only after getting the source by file_get_contents -
i using file_get_contents html source of remote page using code below :
<?php //get url $url = "remotesite/static/section35.html"; $html = file_get_contents($url); $doc = new domdocument(); // create domdocument libxml_use_internal_errors(true); $doc->loadhtml($html); // load html can add $html $elements = $doc->getelementsbytagname('tbody'); $toremove = array(); // gather list of tbodys remove foreach($elements $el) if((strpos($el->nodevalue, 'desktop') !== false) && !in_array($el->parentnode, $toremove, true)) $toremove[] = $el->parentnode; foreach($elements $el) if((strpos($el->nodevalue, 'recommended') !== false) && !in_array($el->parentnode, $toremove, true)) $toremove[] = $el->parentnode; // remove them foreach($toremove $tbody) $tbody->parentnode->removechild($tbody); echo $doc->savehtml(); // save new html ?>
what want remove every h3
closing tage </h3>
source before echo page thos way content appear properly
echo str_replace('</h3>','',$doc->savehtml());
Comments
Post a Comment