适应中文的substr函数

发表于:2007-07-01来源:作者:点击数: 标签:
    function SubstrGB($in,$num){
        $pos=0;
        $out="";
        while($c=substr($in,$pos,1)){
            if($c==" ") break;
            if(ord($c)>128){
                $out.=$c;
                $pos++;
                $c=substr($in,$pos,1);
                $out.=$c;
            }
            else{
                $out.=$c;
            }
            $pos++;
            if($pos>=$num) break;
        }
        return $out;
    }

原文转自:http://www.ltesting.net