加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > Dedecms > 正文

织梦DedeCMS手机站去除文章内容图片自适应

发布时间:2020-12-14 04:08:10 所属栏目:Dedecms 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 大部分手机站都是自适应的,这样图片就不能有宽高限制,我们添加文章图片时很多时候都会有 width height style,在手机站上要把它们清除,又不能影响电

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

大部分手机站都是自适应的,这样图片就不能有宽高限制,我们添加文章图片时很多时候都会有 width height style,在手机站上要把它们清除,又不能影响电脑站的。

{dede:field.body runphp=yes}

global $cfg_basehost;

$str = @me;

$search = '/(<img.*?)width=(["'])?.*?(?(2)2|s)([^>]+>)/is';

$search1 = '/(<img.*?)height=(["'])?.*?(?(2)2|s)([^>]+>)/is';

$search2 = '#(<img.*?.*?)width:d+px;([^"]*?.*?>)#i';

$search3 = '#(<img.*?.*?)height:d+px;([^"]*?.*?>)#i';

$content = preg_replace($search,'$1$3',$str);

$content = preg_replace($search1,$content);

$content = preg_replace($search2,'$1$2',$content);

$content = preg_replace($search3,$content);

@me = $content;

//@me = str_replace('/uploads/allimg/',$cfg_basehost.'/uploads/allimg/',$content);//手机版图片使用绝对路径

{/dede:field.body}

其中

@me = str_replace('/uploads/allimg/',$content);

上述代码表示手机为二级域名时候,将附件地址改为绝对地址,以防止图片打不开的情况出现。

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读