img标签替换为mip-img标签的方法

 成都seo   2018-09-13 17:43   2422 人阅读  0 条评论
摘要:

DEDE自建函数function replaceMipImages($content){    preg_match_all('/<img (.*?)\>/', $content, $images);    if(!is_null($images)) {        foreach($images[1] as $index => $value){    &nbs

DEDE自建函数


function replaceMipImages($content)

{

    preg_match_all('/<img (.*?)\>/', $content, $images);


    if(!is_null($images)) {

        foreach($images[1] as $index => $value){

            $mip_img = str_replace('<img', '<mip-img', $images[0][$index]);

            $mip_img = str_replace('>', '></mip-img>', $mip_img);

            //以下代码可根据需要修改/删除

            $mip_img = preg_replace('/(width|height)="\d*"\s/', '', $mip_img );//移除图片width|height

            $mip_img = preg_replace('/ style=\".*?\"/', '',$mip_img);//移除图片style

            $mip_img = preg_replace('/ class=\".*?\"/', '',$mip_img);//移除图片class

            //以上代码可根据需要修改/删除

            $content = str_replace($images[0][$index], $mip_img, $content);

        }

    }


    return $content;

}

本文地址:http://www.iisya.com/Building/609.html
版权声明:本文为原创文章,版权归 略懂SEO博客 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?