PHP 中文字符串截取

$str = "abcdef啊啊吧啊";

function my_sub($str, $st ,$len){

    $ret = "";
    for( $st; $len > 0; $st++){
        $cStr = $str[$st];
        if( ord( $cStr ) > 127 ){
            $cStr = substr($str, $st, 3);
            $st += 2;
        }
        $len -= 1;
        $ret .= $cStr;
    }
    return $ret;
}

 echo my_sub($str, 3, 6);

 

posted @ 2014-01-07 17:01  ﹏Sakura  阅读(228)  评论(0编辑  收藏  举报