1,可以用iconv_substr,mb_substr,但两者都要加载相应的模块。
2,我以前写的一个比较麻烦的,可以看一下
<?php
   //截取一段字符串
      function gbsub($str,$start,$len){
          $count="0";
          $count1="0";
          $count2="0";
          $count3="0";
          for($i="0";$i<strlen($str);$i++){
              if($count==$start){
                   if(ord($str[$i])>=129){
                       $count1+=0.5;
                   }
                   else{
                       $count1++;
                   }
                   $count3++;
              }
              else{
                 if(ord($str[$i])>=129){
                     $count+=0.5;
                 }
                 else{
                     $count++;
                 }
                 $count2++;
              }              if($count1==$len){
                   break;
              }
          }
          return substr($str,$count2,$count3);
      }      echo gbsub("中国队4:0大胜日本队",8,4);
?>

解决方案 »

  1.   

    稍微简化了一下<?php
       //截取一段字符串
          function gbsub($str,$start,$len){
              $count="0";
              $count1="0";
              $count2="0";
              $count3="0";
              for($i="0";$i<strlen($str);$i++){
                  if($count==$start){
                       $count1+=(ord($str[$i])>=129)?"0.5":1;
                       $count3++;
                  }
                  else{
                      $count+=(ord($str[$i])>=129)?"0.5":1;
                      $count2++;
                  }              if($count1==$len){
                       break;
                  }
              }
              return substr($str,$count2,$count3);
          }      echo gbsub("中国队4:0大胜日本队",4,4);
    ?>
      

  2.   

    //截取混合中英文字符串(与mb_substr一致)
    function sub_string( $text, $start )
    {
    preg_match_all( "/[\x80-\xff]?./", $text, $ar ); if ( func_num_args() >= 3 )
    {
    $end = func_get_arg( 2 );
    return join( '', array_slice( $ar[0], $start, $end ) );
    }
    else
    {
    return join( '', array_slice( $ar[0], $start ) );
    }
    }