DEDECMS织梦文章内容图片img转mip-img
如果使用FCK编辑器,可以直接在里修改【完美解决FCK编辑器上传图片自动带DIV标签的问题】,但是存在一个问题,那就是在编辑器里预览不了,以下的方法更加简单,直接替换img代码为mip-img.
打开/include/extend.func.php,在下面添加如下代码,修改好代码后,在模板里面调用:{dede:field name='body' function='mipBody(@me)'/}这样我们就成功的替换了img为img-mip
function mipBody($body) { $body = str_replace(' style="white-space:pre"', '', $body); preg_match_all('/<img (.*?)\>/', $body, $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); $mip_img = preg_replace('/ style=\".*?\"/', '', $mip_img); $mip_img = preg_replace('/ class=\".*?\"/', '', $mip_img); $body = $content = str_replace($images[0][$index], $mip_img, $body); } } return $body; }
题外话:因为网站的需要,之前修改了编辑器,在手动做链接的时候,希望能从<a herf="xxx">yyy</a>转为mip格式,所以在上面的基础上再稍微修改下,仅此举例。
function mipBody($body) { $body = str_replace(' style="white-space:pre"', '', $body); preg_match_all('/<img (.*?)\>/', $body, $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); $mip_img = preg_replace('/ style=\".*?\"/', '', $mip_img); $mip_img = preg_replace('/ class=\".*?\"/', '', $mip_img); $body = $content = str_replace($images[0][$index], $mip_img, $body); } } preg_match_all('/<a (.*?)>/', $body, $imagess); if (!is_null($imagess)) { foreach ($imagess[1] as $index => $value) { $mip_imgs = str_replace('<a href', '<a data-type="mip" href"', $imagess[0][$index]); $body = $content = str_replace($imagess[0][$index], $mip_imgs, $body); } } return $body; }
推荐栏目
本站推荐
- 修改DEDE链接中的单引号为双引号
- DEDECMS启用绝对路径后远程缩略图存BUG
- 织梦dedecms自由列表的"不使用目录默认
- dedecms把文章批量设为未审核的办法
- 织梦调用父级栏目链接和名称
- 织梦data文件夹移动到程序上一层目录
- 优化增加搜索栏目功能后的搜索结果
- 织梦同级栏目指定文章调用实现相关文章教
- 织梦获取顶级栏目\当前栏目\上级栏目的相
- 织梦dedecms栏目添加自定义字段,增加栏
- 织梦DedeCMS自增函数[field:global name=
- dedecms织梦上传图片 缩略图路径统一
- 新增DEDE栏目页,无法更新,无权限
- 修改织梦摘要长度字数限制
- DEDECMS后台批量替换数据安全码不显示
- 织梦DEDECMS网站标签Tag静态化,生成静态
- 去掉FCK编辑器复制粘贴产生的<p>&a
- 完美解决FCK编辑器上传图片自动带DIV标签
- 去掉FCK编辑器每一段之前的空格 
- 织梦登录后台显示空白
百度站内搜索
Copyright © 2007-2014 海鬼 保留所有权利.
无心无力无时间来进行无用的备案
Theme by 海鬼 坚持不一定胜利 也许你在南辕北辙!