PHP正则过滤采集文章


             $news_info['cont'] = preg_replace('/<\/a>|<a([^>]+?)>/','',$news_info['cont']);
             if(isset($_GET['iphone'])  &&  $_GET['iphone'] ) {
                    $news_info['cont'] = preg_replace('/\d+px/',"50px", $news_info['cont'] );
                    $news_info['cont'] = preg_replace('/font-size[^;]+/i','',$news_info['cont']);
                    $news_info['cont'] = '<style>*{font-size:50px;word-wrap: break-word; word-break:break-all;   }   pre{ /*  white-space: pre-wrap;word-wrap: break-word;*/ overflow:auto; font-size:14px;  }</style>'.$news_info['cont'];  
             }else {
                    $news_info['cont'] = preg_replace('/\d+px/',"24px", $news_info['cont'] );
                    $news_info['cont'] = preg_replace('/font-size[^;]+/i','',$news_info['cont']);
                    $news_info['cont'] = '<style>p{font-size:24px;word-wrap: break-word; word-break:break-all;  }    pre{ /*  white-space: pre-wrap;word-wrap: break-word;*/ overflow:auto; font-size:14px; }</style>'.$news_info['cont'];
                    
             }
             $news_info['cont'] = preg_replace('/<\/script>|<script([^>]+?)>/','',$news_info['cont']);
             $news_info['cont'] = preg_replace('/<\/iframe>|<iframe([^>]+?)>/','',$news_info['cont']);
             $news_info['cont'] = preg_replace('/<\/meta>|<meta([^>]+?)>/','',$news_info['cont']);
             //替换掉图片,仅仅保留图片src
             $news_info['cont'] = preg_replace('/<img([^>]+?)src="([^>]+?)"([^>]+?)>/','<img src="\2">',$news_info['cont']);
             
             //$news_info['cont'] = preg_replace('/<\/meta>|<meta([^>]+?)>/','',$news_info['cont']);
             //$news_info['cont'] = str_ireplace('brush:js;toolbar:false','', $news_info['cont']);
             $news_info['cont'] .= "<script>
                window.onload = function() {
                    var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
                    var imgs = document.querySelectorAll('img');if(imgs.length > 0) {for(var i in imgs) {if(imgs[i].width > w) {imgs[i].width = w-20;}}}
                    var frame = document.querySelectorAll('iframe');if(frame.length > 0) {for(var i in frame) {if(frame[i].width > w) {frame[i].width = w-20;}}}}
                </script>";
             $news_info['cont'] = preg_replace('/(\\t){2,}/',"\t",$news_info['cont']);
             $news_info['cont'] = preg_replace('/(\\n){2,}/',"\n",$news_info['cont']);
             $news_info['cont'] = str_ireplace('<p></p>','',$news_info['cont']);
             $news_info['cont'] = str_ireplace('data-lazyload="','src="',$news_info['cont']);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值