织梦dedecms默认手机模板的文章图片不能自适应屏幕分辨率大小,会造图片显示不完整或者图片将页面撑爆。下面这段代码是通过php代码将文章图片标签的宽度高度全部去掉,以实现屏幕自适应。
编辑手机端文章内容页模板,将里面的{dede:field.body/}标签代码修改为如下的标签代码:
{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.*?style=".*?)width:\d+px;([^"]*?.*?>)#i'; $search3 = '#(<img.*?style=".*?)height:\d+px;([^"]*?.*?>)#i'; $content = preg_replace($search,'$1$3',$str); $content = preg_replace($search1,'$1$3',$content); $content = preg_replace($search2,'$1$2',$content); $content = preg_replace($search3,'$1$2',$content); @me = $content; //@me = str_replace('/uploads/allimg/', $cfg_basehost.'/uploads/allimg/', $content);//手机版图片使用绝对路径 {/dede:field.body}
发表回复