/**
* 移除<img src="" />的HTML元素,避免IE6,IE7,IE8 Session消失
* global smarty filter
* @param string $tpl_output
* @param object $smarty
* @return string
*/
function replace_empty_img($tpl_output, &$smarty) {
/*
*
replace = #
input:
$str = "<img src=\"\" width=\"1\" height=\"1\" />
<br />
<img src=\"\" width=\"2\" height=\"2\" />
<img width=\"3\" src=\" 1\" height=\"3\" />
<img width=\"4\" src= height=\"4\" />
";
output:
<img src="/images_shop/space.gif" width="1" height="1" />
<br />
<img src="/images_shop/space.gif" width="2" height="2" />
<img width="3" src=" 1" height="3" />
<img src="/images_shop/space.gif" width="4" height="4" />
*/
$reg = "/(<img)(.*?)\s+src=(\'\'|\"\"|\"\s+\"|\s+){1}(.*?>)/i";
$replace = IMAGES_URL . 'space.gif';
$tpl_output = preg_replace($reg, "$1 src=\"{$replace}\" $2 $4", $tpl_output);
return $tpl_output;
}
留言