Home > Backend Development > PHP Tutorial > PHP 截取汉语(UTF8版)

PHP 截取汉语(UTF8版)

WBOY
Release: 2016-06-13 13:08:51
Original
1008 people have browsed it

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;
?}
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template