验证中...
Languages: PHP
Categories: Web开发技术
Latest update 2019-03-25 16:14
Common
Raw Copy
/**
* 截取指定长度文本(汉字占两个字节,字母占一个字节,页面编码必须为utf-8)
* @param $str
* @param int $length
* @param string $elli
* @return string
*/
function wordCut($str, $length = 75,$elli = '...') {
//计算字符串长度
$length = $length*2;
$str_len = (strlen($str) + mb_strlen($str,"UTF-8")) / 2;
if($str_len < $length){
return $str;
}
$str = mb_check_encoding($str,"UTF-8")?$str:iconv('gb2312','UTF-8',$str);
$str = mb_strcut(mb_convert_encoding($str, "GBK","UTF-8"), 0, $length, "GBK");
$str = mb_convert_encoding($str, "UTF-8", "GBK");
return $str.$elli;
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search

183227_9af5e6a8_1826025 111910_4d91f001_1826025