PHP截取中文_PHP教程
程序员文章站
2022-05-01 08:34:15
...
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;
}
}
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;
}
}
上一篇: 详细介绍c#读取XML多级子节点
下一篇: php function & 功用