php_cawler_html嵌套标签清洗

主要处理 嵌套 div,正则无法很好的处理清洗 
比如文本: 想要移除 class =quizPutTag 的div  ,内部可能嵌套的还有未知层级的div【前提是html文本段是闭合标签的】
这是<div>test<div class="quizPutTag">test</div><div class="quizPutTag">H<sub>2</sub>C<sub>2</sub>O<sub>4</sub>•2H<sub>2</sub>O<span dealflag="1" class="MathJye" mathtag="math" style="whiteSpace:nowrap;wordSpacing:normal;wordWrap:normal"><table cellpadding="-1" cellspacing="-1" style="margin-right:1px"><tbody><tr><td style="border-bottom:1px solid black;padding-bottom:1px;font-size:90%"><table style="margin-right: 1px" cellspacing="-1" cellpadding="-1"><tbody><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td style="font-size: 90%"><div style="border-top:1px solid black;line-height:1px">.</div></td></tr></tbody></table></td></tr><tr><td>&nbsp;</td></tr></tbody></table></span>CO↑+CO<sub>2</sub>↑+3H<sub>2</sub>O↑</div>保留的</div>
实现code

<?php
   include "./simple_html_dom.php";
   $output="";
   $input=fgets(fopen($argv[1],'r'));
   echo $input."

";
   $html = new simple_html_dom();
   $html->load('<html><body>'.$input.'</body></html>');
   $divsq = $html->find('div.quizPutTag');
   $divsa = $html->find('div.sanwser');
   $output=str_replace($divsq,'___',$input);
   $output=str_replace($divsa,'',$output);
   echo $divs[0]."
";
   echo $html."
";
   $html->clear();
   echo $output."
";

?>

simple_html_dom.php

原文地址:https://www.cnblogs.com/cphmvp/p/4728139.html