function cutstr($str, $length, $dot='…',$charset='utf-8')
{
if(strtolower($charset) == 'utf-8')
{
$str = mb_convert_encoding($str, 'gb2312', 'utf-8');
}
if($length >= strlen($str))
{
return mb_convert_encoding($str, 'utf-8', 'gb2312');;
}
for($i=0;$i<$length-2;$i++)
{
$str_new .= $str[$i];
}
if(strtolower($charset) == 'utf-8')
{
$str_new = mb_convert_encoding($str_new, 'utf-8', 'gb2312');
}
//ord()
return $str_new.$dot;
}
|