function Msubstr ($str, $start =0, $length, $charset = "Utf-8", $suffix =true) {if (Function_exists ("Mb_substr")) {if ($ suffix) {if ($str ==mb_substr ($str, $start, $length, $charset)) {return mb_substr ($str, $start, $length, $charset);} Else{return mb_substr ($str, $start, $length, $charset). " ...";}} Else{return mb_substr ($str, $start, $length, $charset);}} ElseIf (function_exists (' iconv_substr ')) {if ($suffix) {if ($str ==iconv_substr ($str, $start, $length, $charset)) { Return Iconv_substr ($str, $start, $length, $charset);} Else{return iconv_substr ($str, $start, $length, $charset). " ...";}} Else{return iconv_substr ($str, $start, $length, $charset);}} $re [' utf-8 '] = "/[\x01-\x7f]| [\XC2-\XDF] [\x80-\xbf]| [\xe0-\xef] [\X80-\XBF] {2}| [\xf0-\xff] [\X80-\XBF] {3}/"; $re [' gb2312 '] ="/[\x01-\x7f]| [\xb0-\xf7] [\xa0-\xfe]/]; $re [' gbk '] = "/[\x01-\x7f]| [\x81-\xfe] [\x40-\xfe]/]; $re [' big5 '] = "/[\x01-\x7f]| [\x81-\xfe] ([\x40-\x7e]|\xa1-\xfe]) /";p Reg_match_all ($re [$charset], $STR, $match); $slice = Join (" ", Array_slice ($match [0], $start, $), if ($suffix) return $slice. " ... "; return $slice;}
PHP Chinese Cut string length