function SubTitle($String,$Length) {
?if (mb_strwidth($String, 'UTF8') <= $Length ){
??return $String;
?}else{
??$I = 0;
??$len_word = 0;
??while ($len_word < $Length){
???$StringTMP = substr($String,$I,1);
???if ( ord($StringTMP) >=224 ){
????$StringTMP = substr($String,$I,3);
????$I = $I + 3;
????$len_word = $len_word + 2;
???}elseif( ord($StringTMP) >=192 ){
????$StringTMP = substr($String,$I,2);
????$I = $I + 2;
????$len_word = $len_word + 2;
???}else{
????$I = $I + 1;
????$len_word = $len_word + 1;
???}
???$StringLast[] = $StringTMP;
??}
??/* raywang edit it for dirk for (es/index.php)*/
??if (is_array($StringLast) && !empty($StringLast)){
???$StringLast = implode("",$StringLast);
???$StringLast .= "...";
??}
??return $StringLast;
?}
}
详细解决方案
PHP 截取汉语(UTF8版)
热度:39 发布时间:2016-04-28 23:21:21.0
相关解决方案
- big5 utf8 sqlserver编码有关问题
- svn: 索引中的条目从本地编码转换到 UTF8 失败
- 使用"SET NAMES UTF8"后,出现乱码解决思路
- jsp utf 乱码异常 com.caucho.jsp.JspParseException: illegal utf8 encoding at 0xdf
- query.exec("set names utf8") 这是啥意思,该怎么处理
- Android中检测字符编码(GB2312,ASCII,UTF8,UNICODE,TOTAL——ENCODINGS)步骤(二)
- C# 中 UTF8Encoding.UTF8.GetBytes(key),对应PHP中的哪个方法? 如何写
- 使用"SET NAMES UTF8"后,出现乱码解决思路
- MySQL 怎么修改字符集 utf8 改为 utf8mb4
- utf8-to-utf8mb4 mysql支持全部unicode
- 前端中常见字节编码(base64、hex、utf8)及其转换
- 使用Ant编译过程中,报error: unmappable character for encoding UTF8
- VB不使用 API,将 Utf8 转换为 Unicode
- Windows下的字符集转换(ASCII、UICODE、UTF8、GB2312和BIG5互转)
- UTF-8在IE中不能自动选择编码的解决办法(utf8 网页在ie中自动编码乱码问题)
- UTF8/ANSI/UNICODE文件读取
- 用ant编译时出现“编码 UTF8 的不可映射字符“,这是因为编译的时候编码跟文件存储的编码方式不一样造成的
- 对字符编码与Unicode,ISO 10646,UCS,UTF8,UTF16,GBK,GB2312的理解
- 火车头采集器 内容发布 utf8 模板 utf-8 乱码