mbstring,用phpinfo看一下是否安装
http://ca3.php.net/manual/en/ref.mbstring.php

解决方案 »

  1.   

    if(ord(substr($str,$i,1))>0xa0) $j++;
    ===>
    if(ord(substr($str,$i,1))>0x80) $j++;
      

  2.   

    多谢唠叨!
    问题有所改善.
    但是
    substrgb("█ Canon 扫描仪 █",14);
    得到的是:
    █ Canon 扫描?..问题还是存在.是这个下限值的问题,还是这种做法跟本就不合适呢?
      

  3.   

    试试这个吧,█的代码正好是A880if(ord(substr($str,$i,1))>=0x80) $j++;
      

  4.   

    你的函数本身是有毛病的,不过既然函数名中有gb字样,那么就不要指望能处理繁体字了
    另外,这个算法在$strlen叫大时是非常耗时的
    function substrgb($str,$strlen=10,$other=true) {
    $i=0;
    while($i<$strlen) {
    if(ord($str[$i]) > 0x80) $i++;
    $i++;
    }
    $rstr = substr($str,0,$i);
    if (strlen($str)>$strlen && $other) {$rstr.=' ...';}
    return $rstr;
    }
      

  5.   

    <?php
    function c_substr($str,$start=0) {
      $ch = chr(127);
      $p = array("/[\x81-\xfe]([\x81-\xfe]|[\x40-\xfe])/","/[\x01-\x77]/");
      $r = array("","");
      //func_num_args,func_num_args 可变参数函数列表
      if(func_num_args() > 2)
        $end = func_get_arg(2);
      else
        $end = strlen($str);
      if($start < 0)
        $start += $end;  if($start > 0) {
        $s = substr($str,0,$start);
        if($s[strlen($s)-1] > $ch) {
          $s = preg_replace($p,$r,$s);
        $start += strlen($s);
        }
      }
      $s = substr($str,$start,$end);
      $end = strlen($s);
      if($s[$end-1] > $ch) {
        $s = preg_replace($p,$r,$s);
        $end += strlen($s);
      }
      return substr($str,$start,$end);
    }echo c_substr("█ Canon 扫描仪 █",14);
    ?>
      

  6.   

    sorry,上面的
    echo c_substr("█ Canon 扫描仪 █",14);
    改为
    echo c_substr("█ Canon 扫描仪 █",0,14);