php_cawler_html嵌套标签清洗
2015-08-13 18:29
751 查看
主要处理 嵌套 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> △ </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> </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
相关文章推荐
- php 去除html标记--strip_tags与htmlspecialchars的区别详解
- redhat7.1 vsftp root用户上传
- PHP 创建、增加、删除、修改 xml
- php常用库函数
- php实现几种排序
- 优雅的使用 PhpStorm 来开发 Laravel 项目
- Laravel SoapClient
- selectpicker下拉多选框ajax异步或者提前赋值=》默认值(2)
- php回传ajax数据
- PHP文件操作
- PHP Client for Mysql Binlog
- 如何使用PHP上传文件,上传图片,php上传教程,php表单文件上传教程
- 华三交换机mstp生成树配置
- (转)基于PHP——简单的WSDL的创建(WSDL篇)
- 转载:setAttribute和setParameter方法的区别
- 使用PHP QR Code生成二维码
- PHP菜鸟手记——如何解决无法装载动态链接库的问题
- win8和win7下解决php5.3和5.4、5.5等不能加载php_curl.dll的终极解决办法
- PHP学习总结(四)
- phpstorm快捷键