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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM