img转mip-img,过滤style属性,过滤 script脚本
如下代码加入到:/include/extend.func.php
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);
}
}
$body = preg_replace(array("/style=(.*?)>/i"),array(">"),$body);
$body = preg_replace(array("/<script(.*?)script>/i"),"",$body);
return $body;
}
模板里面调用:
{dede:field.body function='mipBody(@me)'/}