php截取中文字符串 GB2312 utf-8
2014-07-31 15:21
495 查看
UTF-8截取中文字符串 function Cn_Substr($string, $length) { preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $info); for($i=0; $i<count($info[0]); $i++) { $wordscut .= $info[0][$i]; $j = ord($info[0][$i]) > 127 ? $j + 2 : $j + 1; if ($j > $length - 3) { return $wordscut." ..."; } } return join('', $info[0]); } GB2312截取中文字符串 function Cn_Substrs($strs,$lens){ if (strlen($strs)<$lens) { $nstrs=$strs; }else{ $mlens=$lens; for ($i=0;$i<=strlen($strs) && $mlens>0;$i++){ $chars=substr($strs,$i,1); if(ord($chars)>0xa0 ) { $i++; $mlens -=2;; }else{ $mlens--; } } $nstrs=substr($strs,0,$i)."..."; } return $nstrs; }
相关文章推荐
- PHP字符串截取函数(解决中文乱码问题!支持UTF-8和GB2312)
- php smarty截取中文字符乱码问题?gb2312/utf-8
- PHP字符串截取函数支持utf和gb2312
- PHP截取字符串编码(兼容utf-8和gb2312)
- PHP 截取中文字符串 UTF-8
- php smarty截取中文字符乱码问题?gb2312/utf-8
- php截取utf-8中文字符串乱码的解决方法
- PHP 字符串编码截取函数(兼容utf-8和gb2312)
- 用php截取utf-8中文字符串乱码的解决方法
- js 与 php 验证 判断 utf-8 与 GB2312 中文字符串
- PHP 字符串编码截取函数(兼容utf-8和gb2312)
- 共享:在UTF-8编码情况下PHP截取中文字符串的代码
- PHP 中文字符串截取函数(UTF-8)有效
- PHP中截取UTF-8中文字符串
- PHP中的中文截取乱码问题_gb2312_utf-8
- [PHP] - 中文字符串截取(UTF-8与非UTF-8)
- PHP utf-8中文截取无乱码(字符串判断版本)
- php自定义中文字符串截取函数substr_for_gb2312及substr_for_utf8示例
- php自定义中文字符串截取函数substr_for_gb2312及substr_for_utf8示例
- php字符串截取函数(支持中文 utf-8截取)