Heim  >  Artikel  >  Backend-Entwicklung  >  PHP截取中文_PHP教程

PHP截取中文_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:45:10823Durchsuche

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478688.htmlTechArticlefunction SubTitle($String,$Length) { if (mb_strwidth($String, UTF8) = $Length ){ return $String; }else{ $I = 0; $len_word = 0; while ($len_word $Length){ $StringTMP = substr($Strin...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php生成uuid_PHP教程Nächster Artikel:PHP中getenv函数_PHP教程