/**
* 可以统计中文字符串长度的函数
*
*/
function abslength($str)
{
$len=strlen($str);
$i=0;
while($i<$len)
{
if(preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/",$str[$i]))
{
$i+=2;
}
else
{
$i+=1;
}
}
return $i;
}
mb_strlen($str, 'GBK');
function StrLenW($str)
{
$count = 0;
$len = strlen($str);
for($i=0; $i<$len; $i++,$count++)
if(ord($str[$i])>=128)
$i++;
return $count;
}
/**作用:统计字符长度包括中文、英文、数字
* 参数:需要进行统计的字符串、编码格式目前系统统一使用UTF-8
* 修改记录:
$str = "kds";
echo sstrlen($str,'utf-8');
* */
function sstrlen($str,$charset) {
$n = 0; $p = 0; $c = '';
$len = strlen($str);
if($charset == 'utf-8') {
for($i = 0; $i < $len; $i++) {
$c = ord($str{$i});
if($c > 252) {
$p = 5;
} elseif($c > 248) {
$p = 4;
} elseif($c > 240) {
$p = 3;
} elseif($c > 224) {
$p = 2;
} elseif($c > 192) {
$p = 1;
} else {
$p = 0;
}
$i+=$p;$n++;
}
} else {
for($i = 0; $i < $len; $i++) {
$c = ord($str{$i});
if($c > 127) {
$p = 1;
} else {
$p = 0;
}
$i+=$p;$n++;
}
}
return $n;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有