PHP 截取汉语(UTF8版)

WBOY
发布: 2016-06-13 13:08:51
原创
996 人浏览过

PHP 截取中文(UTF8版)

function SubTitle($String,$Length) {
?if (mb_strwidth($String, 'UTF8') ??return $String;
?}else{
??$I = 0;
??$len_word = 0;
??while ($len_word ???$StringTMP = substr($String,$I,1);
???if ( ord($StringTMP) >=224 ){
????$StringTMP = substr($String,$I,3);
????$I = $I + 3;
????$len_word = $len_word + 2;
???}elseif( ord($StringTMP) >=192 ){
????$StringTMP = substr($String,$I,2);
????$I = $I + 2;
????$len_word = $len_word + 2;
???}else{
????$I = $I + 1;
????$len_word = $len_word + 1;
???}
???$StringLast[] = $StringTMP;
??}
??/* raywang edit it for dirk for (es/index.php)*/
??if (is_array($StringLast) && !empty($StringLast)){
???$StringLast = implode("",$StringLast);
???$StringLast .= "...";
??}
??return $StringLast;
?}
}

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板