设为首页 - 加入收藏
广告 1000x90
您的当前位置:主页 > 网站运营 > 正文

dedecms织梦手机站去除文章内容中图片的宽高达到自适应

来源:网络分享 编辑:引流技巧 时间:2026-05-10

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

01 {dede:field.body runphp=yes}

02 global $cfg_basehost;

03 $str = @me;

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

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

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

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

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

09 $content = preg_replace($search1,'$1$3',$content);

10 $content = preg_replace($search3,'$1$2',$content);

11 $content = preg_replace($search3,'$1$2',$content);

12 @me = $content;

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

14 {/dede:field.body}

其中

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

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

相关推荐:

栏目分类

微商引流技巧网 www.yinliujiqiao.com 联系QQ:1716014443 邮箱:1716014443@qq.com

Copyright © 2019-2024 强大传媒 吉ICP备19000289号-9 网站地图 rss地图

Top