PHP 中文字符串截取

原文链接: http://www.cnblogs.com/glory-jzx/p/3509229.html
$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);

转载于:https://www.cnblogs.com/glory-jzx/p/3509229.html

猜你喜欢

转载自blog.csdn.net/weixin_30781631/article/details/94800775