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

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; }

 

posted on 2017-10-10 09:31  dongruiha  阅读(2700)  评论(0编辑  收藏  举报

导航