现在大部分站长所做的站都是自适应的,这样图片就不能有宽高限制。然而我们在使用dedecms后台管理系统添加文章图片时很多时候都会有width height style这些属性在里面,当使用手机浏览时就会出现图片变形,所以我们需要在把它们清除,今天分享的这种方法就可以实现并且让图片和附件都使用上绝对路径。
内容页去除图片style样式
{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:\s{0,}\d+px;([^"]*?.*?>)#i';
$search3 = '#(<img.*?style=".*?)height:\s{0,}\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 = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content);
{/dede:field.body}
栏目内容去除图片style样式
{dede:field.content/}
修改成:
{dede:field.content 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:\s{0,}\d+px;([^"]*?.*?>)#i';
$search3 = '#(<img.*?style=".*?)height:\s{0,}\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 = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content);
{/dede:field.content}
另外提示:在写css样式时可对内容的图片加上
max-width: 100%
这样图片就不会挤出框架外面了。
版权声明:本文由Dedeking于2019-08-29 16:05发表。
转载请注明:织梦上传图片去除自动添加的宽高+绝对路径图片-【织梦King】dede仿站教程网
转载请注明:织梦上传图片去除自动添加的宽高+绝对路径图片-【织梦King】dede仿站教程网
打赏
咨询