http://expert.csdn.net/Expert/topic/2066/2066774.xml?temp=.7522547

解决方案 »

  1.   

    $rest = substr("abcdef", 1);    // returns "bcdef" 
    $rest = substr("abcdef", 1, 3); // returns "bcd" 
    $rest = substr("abcdef", 0, 4); // returns "abcd" 
    $rest = substr("abcdef", 0, 8); // returns "abcdef" 
      

  2.   

    c_substr按字节计算,即一个汉字的长度为2;m_substr按字计算,即一个汉字的长度为1。可根据需要选用。function c_substr($str,$start=0) {
      $ch = chr(127);
      $p = array("/[\x81-\xfe]([\x81-\xfe]|[\x40-\xfe])/","/[\x01-\x77]/");
      $r = array("","");
      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);
    }function m_substr($str,$start) {
      preg_match_all("/[\x80-\xff]?./",$str,$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));
    }