/*
- * @todo Chinese intercept, support GB2312,GBK,UTF-8,BIG5
- * @http://bbs.it-home.org
- * @param string $str the string to intercept
- * @param int $start intercept start position
- * @param int $length intercept length
- * @param string $charset UTF-8|GB2312|GBK|BIG5 encoding
- * @param $suffix whether to add suffix
- */
function Csubstr ($str, $start =0, $length, $charset = "Utf-8", $suffix =true)
- {
- if (function_exists ("Mb_substr"))
- Return Mb_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]) /";
- Preg_match_all ($re [$charset], $STR, $match);
- $slice = Join ("", Array_slice ($match [0], $start, $length));
- if ($suffix) return $slice. " ...";
- return $slice;
- }
- ?>
Copy CodeThe above code, looking at the bull X, to know the PHP regular, that is pretty tough. Copy the above code, test it on your machine, and do more hands-on, helping to improve the programming level quickly. |