PHP intercepts Chinese (UTF8) functionSubTitle ($ String, $ Length ){? If (mb_strwidth ($ String, 'utf8') & lt; = $ Length ){?? Return $ String ;?} Else {?? $ I PHP intercepts Chinese (UTF8)
Function SubTitle ($ String, $ Length ){
? If (mb_strwidth ($ String, 'utf8') <= $ Length ){
?? Return $ String;
?} Else {
?? $ I = 0;
?? $ Len_word = 0;
?? While ($ len_word <$ Length ){
??? $ StringTMP = substr ($ String, $ I, 1 );
??? If (ord ($ StringTMP) & gt; = 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;
?}
}