函數cut_str($string,$sublen,$start = 0,$charset = 'UTF-8 ')
{
if($charset == 'UTF-8 ')
{
$ pa = "/[\ x 01-\ x7f]|[\ xc2-\ xdf][\ X80-\ xbf]| \ xe0[\ xa0-\ xbf][\ X80-\ xbf]|[\ xe 1-\ xef][\ X80-\ xbf][\ X80-\ xbf]| \ xf 0[\ x90-\ xbf][\ X80-\ xbf][\ X80-\ xbf][\ xbf][\ X80-\ xbf][\ xbf]
preg_match_all($pa,$string,$ t _ string);
if(count($ t _ string[0])-$ start & gt;$sublen)返回join(',array_slice($t_string[0],$start,$sublen))。"...";
return join(' ',array_slice($t_string[0],$start,$ sub len));
}
其他
{
$ start = $ start * 2;
$ sub len = $ sub len * 2;
$ strlen = strlen($ string);
$ tmpstr =“”;
for($ I = 0;$ i & lt$ strlen$i++)
{
if($ I & gt;= $ start & amp& amp$ i & lt($start+$sublen))
{
if(ord(substr($string,$i,1))>129)
{
$tmpstr。= substr($string,$i,2);
}
其他
{
$tmpstr。= substr($string,$i,1);
}
}
if(ord(substr($string,$i,1))>129)$ i++;
}
if(strlen($ tmpstr)& lt;$strlen ) $tmpstr。= "...";
返回$ tmpstr
}
}