Archive for 十一月, 2008

UTF-8 GBK下PHP获取字符串长度

UTF-8 GBK下PHP获取字符串长度,是langwan写的,贴过来大家分享,完美的解决了PHP下获取UTF-8或者GBK字符集的字符串长度问题!/** 统计字符串长度 *@author langwan *@param $str 被统计字符串*/function sstrlen($str) { global $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; }...

中文字符长度

//中文字符长度,一个中文长度为1。 function cstrlen($str){ $n = 0; $p = 0; $c = ''; $len = strlen($str);for($i = 0; $i < $len; $i++) { $c = ord($str{$i}); if($c > 127) { $p = 1; } else { $p = 0; } $i+=$p;$n++; }return...

截取字符串-InterceptString

'************* 截取字符串 **************function InterceptString(txt,length) txt=trim(txt) x = len(txt) y = 0 if x >= 1 then for ii = 1 to x if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then '如果是汉字 y = y + 2 else y = y + 1 end if if y >= length then txt = left(trim(txt),ii) '字符串限长 exit for end if next InterceptString = txt else InterceptString = "" end ifEnd...

测字符串长度-CheckStringLength

'*************测字符串长度**************Function CheckStringLength(txt) txt=trim(txt) x = len(txt) y = 0 for ii = 1 to x if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then '如果是汉字 y = y + 2 else y = y + 1 end if next CheckStringLength = yEnd...