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."\n\n";
   $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]."\n";
   echo $html."\n";
   $html->clear();
   echo $output."\n";

?>

 


simple_html_dom.php

转载于:https://www.cnblogs.com/cphmvp/p/4728139.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值