网页预览 html过滤标签
2012-10-09 11:33
309 查看
今天新写了了网页预览的接口,需要把原来网页的css js全部过滤掉,并且添加一个统一的css样式,功能实现并不复杂,但是还是花了不少时间。把代码贴过来。
public function preview(){ $url=$_GET['url']; $url="http://192.168.0.112:8088/search/cache/?url=".$url; $html = file_get_contents($url); $encode = mb_detect_encoding($html, array('UTF-8','GB2312','GBK','BIG5','ASCII')); //echo $encode; //header("Content-Type: text/html; charset=UTF-8"); $basic_css='<head><style type="text/css"> body{line-height:1.3em;font-size:13px;}img{border:medium none;}form{margin:0;}.bc{background-color:#CCECFF;font-size:13px;} .in{margin-bottom:5px;} .c0{word-wrap:break-word;}.c1{margin:0;padding:0;}.c2{color:rgb(198, 10, 0);background-color:rgb(255, 255, 255);}.c3{font-weight:bold;}.c4{border-top:5px solid rgb(0, 0, 0);}.c5{word-break:break-all;padding-right:8px;vertical-align:top;display:inline-block;max-width:150px;}.c6{width:140px;}.c7{border:none;}.c8{word-break:break-all;padding-right:8px;vertical-align:top;display:inline-block;max-width:75px;}.c9{width:65px;} .z{margin: 5px 0 5px 0;background-color:#E4EDF8;padding-left:3px}.z a{color:#554;font-size:14px;text-decoration:none;} .nav2{color:#000000;background-color:#E1E1F9;} .footer{margin-top:8px;padding-top:8px;clear:both;} .footer a{color:#00e} .tc_relate { margin-top: 19px; font-size: 15px;color:#039} .tc_h_touch { height: 27px; line-height: 27px; border: 1px solid #C9C9C9;border-width: 1px 0;padding-left: 10px;background:#E4EDF8;line-height: 27px;font-size: 15px;} .i_search { font-size: 15px; margin-bottom: 11px; } .i_search { padding: 0 6px;} #f_3 a{color:#039} #f_2 a{color:#039} </style>'; //echo $html; $str = $html; $str = preg_replace( "@<script(.*?)</script>@is", "", $str ); $str = preg_replace( "@<iframe(.*?)</iframe>@is", "", $str ); $str = preg_replace( "@<link(.*?)/>@is", "", $str ); $str = preg_replace( "@<style(.*?)</style>@is", "", $str ); $str = preg_replace( "@<head>@is", $basic_css, $str ); //$str = preg_replace( "@<(.*?)>@is", "", $str ); echo $str; } }
相关文章推荐
- java+Jsoup 正则过滤html网页标签【多线程数据采集之二】
- asp.net正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- asp.net正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- java+Jsoup 正则过滤html网页标签【多线程数据采集之二】
- ASP.NET正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- PHP实现网页内容html标签补全和过滤的方法小结【2种方法】
- asp.net正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- asp.net正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- java+Jsoup 正则过滤html网页标签【多线程数据采集之二】
- asp.net正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- 网页内容的html标签补全和过滤的两种方法
- java+Jsoup 正则过滤html网页标签【多线程数据采集之二】
- 过滤网页中的HTML标签C++代码
- 网页内容的html标签补全和过滤的两种方法
- [python] 常用正则表达式爬取网页信息及分析HTML标签总结
- 网页HTML代码中Meta标签详解
- HTML中设置网页自适应的MATE标签
- asp.net正则表达式提取网页网址、标题、图片,滤所有HTML标签
- HTML学习之网页制作基础和常用标签及标签属性
- PHP过滤常见html标签的正则表达式