sp扩展自动去掉html并截取字符的函数支持utf8

#1 xpp1000

function utf8shtml($params)
{$str=$params["str"];
$str = trim($str);
$str = strip_tags($str,"");
$str = ereg_replace("\t","",$str);
$str = ereg_replace("\r\n","",$str);
$str = ereg_replace("\r","",$str);
$str = ereg_replace("\n","",$str);
$str = ereg_replace(" "," ",$str);
$from=$params["from"];
$len=$params["len"];
return preg_replace('^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
                       '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*s',
                       '$1',$str);
}

spAddViewFunction('utf8shtml','utf8shtml');

2011-05-30 16:04:28

#2 7666345

杀花 ~~~~

2011-05-30 16:07:17

#3 xpp1000

什么意思不明白

2011-05-30 16:09:52

#4 7666345

沙发 ~~
~

2011-05-30 16:10:59

#5 anythink

这玩意截取的准确吗??? 是不是把所有html标签都去了?

2011-07-12 09:09:32

#6 xpp1000

恩经过测试正常情况,98%可以过

2011-08-01 17:47:26

#7 jake

ereg_replace那部分可以用str_replace,参数可以是数组形态。这样更节省资源。

2011-08-01 21:21:28