img标签替换为mip-img标签的方法
2024-09-01 14:53:35
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;
}
最新文章
- Spring和SpringMVC父子容器关系初窥
- 【230】4T硬盘如何完全利用(GPT)
- jquery输入数字随机抽奖特效
- MYSQL的锁介绍,以及死锁发生情况-带例子
- java语句类型
- linux 列出安装包内的文件
- Mysql 建表时,日期时间类型选择
- $Django RESTful规范
- Sublime text 3搭建Python开发环境及常用插件安装
- Spring ApplicationListener使用方法及问题
- ThinkPHP验证码类的使用
- SAP Overview
- zsh与oh-my-zsh
- C#-流、存储
- block本质探寻六之修改变量
- opensips安装
- MySQL 开启事件 使用定时器调用存储过程
- 【Python】循环设计
- 【eclipse新增系列】eclipse新安装设计编码统一
- Oracle RMAN 学习:恢复
热门文章
- SpringBoot LoggerFactory is not a Logback LoggerContext but Logback is on the classpath
- 【转】Java8中list转map方法总结
- vue 之 render 函数不能渲染非全局自定义函数-方案
- Spring入门篇——AOP基本概念
- httprunnermanager环境搭建 -----转
- Java中程序初始化的顺序
- idea 复制多条字符串
- 后端数据中含有html标签和css样式,前端如何转译展示样式效果。
- BZOJ 3901 棋盘游戏 (找结论+枚举+贪心)
- sync、fsync和fdatasync