织梦dedecms MIP改造图片img转img-mip处理方法
网站建设 2022-07-27 08:13www.1681989.com免费网站
MIP 十分关注页面速度,也禁用了一些引起拖慢速度的HTML 标签(禁用列表)。例如,标签会引起浏览器的repat 和reflow,为了避免这些,MIP 提供了替代标签。下面淘站网为大家介绍d […]



MIP 十分关注页面速度,也禁用了一些引起拖慢速度的HTML 标签(禁用列表)。例如,标签会引起浏览器的repat 和reflow,为了避免这些,MIP 提供了替代标签。下面淘站网为大家介绍dedecms开发中img转img-mip的处理方法。

在/clude/extend.func.php里添加如下代码

function mipBody($body)
{
    $body = str_replace(' style="white-space:pre"', '', $body);
    preg_match_all('//', $body, $images);
    if (!is_null($images)) {
        foreach ($images[1] as $dex => $value) {
            $mip_img = str_replace('<img', '', '>', $mip_img);
            $mip_img = preg_replace('/(width|height)="\d"\s/', '', $mip_img);
            $mip_img = preg_replace('/ style=\".?\"/', '', $mip_img);
            $mip_img = preg_replace('/ class=\".?\"/', '', $mip_img);
            $body = $content = str_replace($images[0][$dex], $mip_img, $body);
        }
    }
    return $body;
}

在模板里面调用

{dede:field name='body' function='mipBody(@me)'/}

Copyright © 2016-2025 www.1681989.com 推火网 版权所有 Power by