这有区别吗?
我用
for($i=0;$i<strlen($option);$i++){
  $subop=substr($option,$i,($i+1));
  $newoption=$newoption+$subop+"%";
}
没有用~~~~
正确的用法应该是什么?

解决方案 »

  1.   

    <?php
    /////////////////////////////////////////////////
    //
    // 输入 :将要输出的字符串及长度
    // 输出 :字符串
    // 功能 :按指定长度输出字符串
    //
    ///////////////////////////////////////////////////
      function autocut ($string,$length)
      {
       $n=0;
       $out="";
       for($i=0;$i<$length;$i++)
       {
          $char=substr($string,$n,1);
          $char_num=ord($char);
          if($char_num<=160)
             {
              $out.=$char;
              $n=$n+1;
              continue;
             }
          else
                  {
                          $home=$char;
                          $n=$n+1;
                          $next=substr($string,$n,1);
                          $next_num=ord($next);
                            if($next_num>160)
                            {
                                    $str=$home.$next;
                                    $out.=$str;
                                    $n=$n+1;
                                    continue;
                            }
                            else
                            {
                                    $out.=$next;
                                    $n=$n+1;
                                    contunue;
                            }              }      }
          echo $out;
      }
    ?>
    这个函数可以把一个汉字当一个字符外理拿去用吧!