DedeCMS织梦

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

阿里云

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

  1. {dede:field.body runphp=yes}
  2. global $cfg_basehost;
  3. $str = @me;
  4. $search = '/(<img.*?)width=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
  5. $search1 = '/(<img.*?)height=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
  6. $search2 = '#(<img.*?style=".*?)width:\d+px;([^"]*?.*?>)#i';
  7. $search3 = '#(<img.*?style=".*?)height:\d+px;([^"]*?.*?>)#i';
  8. $content = preg_replace($search,'$1$3',$str);
  9. $content = preg_replace($search1,'$1$3',$content);
  10. $content = preg_replace($search2,'$1$2',$content);
  11. $content = preg_replace($search3,'$1$2',$content);
  12. @me = $content;
  13. //@me = str_replace('/uploads/allimg/', $cfg_basehost.'/uploads/allimg/', $content);//手机版图片使用绝对路径
  14. {/dede:field.body}
也想出现在这里?联系我们
创客主机

其中

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

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

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

已有 382 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!