php 正则采集获取文章,PHP正则过滤采集文章

本文通过JavaScript调整元素尺寸,实现文章内容在不同设备上的自适应,确保在iPhone和常规屏幕下有良好的阅读体验。内容中图片和iframe大小被限制,同时移除了多余元数据。焦点在于提高网页的可读性和跨平台兼容性。
摘要由CSDN通过智能技术生成

$news_info['cont'] = preg_replace('/|]+?)>/','',$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'] = ''.$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'] = ''.$news_info['cont'];

}

$news_info['cont'] = preg_replace('/|

$news_info['cont'] = preg_replace('/<\/iframe>|]+?)>/','',$news_info['cont']);

$news_info['cont'] = preg_replace('/<\/meta>|]+?)>/','',$news_info['cont']);

//替换掉图片,仅仅保留图片src

             $news_info['cont'] = preg_replace('/]+?)src="([^>]+?)"([^>]+?)>/','\2',$news_info['cont']);

//$news_info['cont'] = preg_replace('/<\/meta>|]+?)>/','',$news_info['cont']);

//$news_info['cont'] = str_ireplace('brush:js;toolbar:false','', $news_info['cont']);

$news_info['cont'] .= "

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;}}}}

";

$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('

$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、付费专栏及课程。

余额充值