试下这个函数<?
 function tsubstr($str,$start=0,$len=46)
 {
  if($start< 0 && $len < 0)
  {
   return $str; 
  }  
  if(($start+$len) >= strlen($str))
  {   
   return substr($str,$start,$len);   
  }
  else
  {
   $j=0;
          $num=$len;
          for($i=$start; $i< $num-1;$i++)
          {
           if(ord(substr($str,$i,1))>0xa0) $j++;
          }
          if($j%2!=0)
           {
                  $num=$num+1;
           }else
           {
                  $num=$num;
           }
           return substr($str,$start,$num-1)."..."; 
  }
 }
?>

解决方案 »

  1.   

    基本能用,不是很完善。
    $str='ch中国ina';
    preg_match_all("/\w|[\\x00-\\xff]{2}/",$str,$r);
    print_r($r);
      

  2.   

    字串的逐字输出:http://blog.tonyang.com/?action=show&id=126
    $output = null;
    $str='我sdfg爱dfg16d到访撒旦飞4!@#你abddd';
    preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/", $str, $output);
    print_r($output[0]);
    ------------------Output:
    Array
    (
        [0] => 我
        [1] => s
        [2] => d
        [3] => f
        [4] => g
        [5] => 爱
        [6] => d
        [7] => f
        [8] => g
        [9] => 1
        [10] => 6
        [11] => d
        [12] => 到
        [13] => 访
        [14] => 撒
        [15] => 旦
        [16] => 飞
        [17] => 4
        [18] => !
        [19] => @
        [20] => #
        [21] => 你
        [22] => a
        [23] => b
        [24] => d
        [25] => d
        [26] => d
    )
      

  3.   

    格式乱了,重新发!$output   =   null;
    $str='我sdfg爱dfg16d到访撒旦飞4!@#你abddd';
    preg_match_all("/[\x01-\x7f] ¦[\xc2-\xdf][\x80-\xbf] ¦[\xe0-\xef][\x80-\xbf]{2} ¦[\xf0-\xff][\x80-\xbf]{3}/",   $str,   $output);
    print_r($output[0]);
      

  4.   


    <?php
    $words='ch中国ina';
    preg_match_all("/(([a-zA-Z]{1})|([\S]{2}))/e",$words,$match);
    echo '|';print_r($match[0]);die("|end");
    ?>
    Array
    (
        [0] => c
        [1] => h
        [2] => 中
        [3] => 国
        [4] => i
        [5] => n
        [6] => a
    )不要把问题复杂化.
      

  5.   

    格式还是不对:)
    帮你再发遍.<?php
    $str='ch中国ina!as5d4as54d6asdas6456';
    preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/",$str,$r);
    print_r($r);
    ?>http://blog.tonyang.com/?action=show&id=126这个应该是最好的方案了,可以分开特殊符号.