PHP获取字符串中英文混合长度
来源:互联网 发布:鲸鱼搁浅的原因知乎 编辑:程序博客网 时间:2024/05/16 19:35
/**
* @param $str string 字符串
* @param $$charset string 编码
* @return 返回长度,1中文=1位,2英文=1位
* @param $str string 字符串
* @param $$charset string 编码
* @return 返回长度,1中文=1位,2英文=1位
*/
function strLength($str,$charset='utf-8'){
if($charset=='utf-8') $str = iconv('utf-8','gb2312',$str);
$num = strlen($str);
$cnNum = 0;
for($i=0;$i<$num;$i++){
if(ord(substr($str,$i+1,1))>127){
$cnNum++;
$i++;
}
}
$enNum = $num-($cnNum*2);
$number = ($enNum/2)+$cnNum;
return ceil($number);
}
0 0
- PHP获取字符串中英文混合长度
- PHP获取字符串中英文混合长度
- PHP获取中英文混合字符串长度及截取
- php混合字符串长度和截取 中英文
- 中英文混合字符串长度
- 3种获取中英文混合字符串长度的方法
- javascript获取中英文混合字符串的长度方法
- 得到中英文混合字符串长度
- 得到中英文混合字符串长度
- 判断字符串长度,中英文混合
- 得到中英文混合字符串长度
- 计算中英文混合字符串长度
- 获取中英文字符串长度
- PHP如何获取混合中文字符串长度
- php截取中英文混合字符串
- PHP如何获取中文和 中英文混字符串长度
- 按指下长度分拆中英文混合字符串!!!!
- 计算中英文混合字符串的长度
- wailterphp的start
- nstring nsdata byte char 之间关系
- Android自定义attr和style
- Ubuntu14.04(32位)下安装使用docker
- android EditText中的inputType
- PHP获取字符串中英文混合长度
- 异步加载AsyncTask
- 一定要心平气和
- ffmpeg源码跟踪笔记之avformat_open_input
- 1001-HBase基本概念
- SDUT 1214 天仙配
- asp.net md5加密
- nsis入门精解教程
- 更轻的JSON