PHP统计utf8中文字符个数
PHP #中文 #字数 #函数2012-05-24 22:18
这个函数还是很常用的,收藏下吧。
01 | <?php |
02 | function Counti( $str ) |
03 | { |
04 | $ch_amont = 0; |
05 | $en_amont = 0; |
06 | $str = preg_replace( "/( | ){1,}/" , " " , $str ); |
07 | for ( $i =0; $i < strlen ( $str ); $i ++) |
08 | { |
09 | $ord = ord( $str { $i }); |
10 | if ( $ord > 128) |
11 | $ch_amont ++; |
12 | else |
13 | $en_amont ++; |
14 | } |
15 | return ( $ch_amont /3) + $en_amont ; |
16 | } |
17 |
18 | echo $str = '一个网在线教程#$时间%^yige.org' ; |
19 | echo "<br/>" ; |
20 | echo Counti( $str ); |
21 | ?> |
相关文章
- 出现Unable to find the socket transport 'ssl' 解决方法 2012/05/23
- jquery循环map/数组/对象的方法 2012/05/20
- Call to undefined function curl_init()错误的解决方法 2012/05/20
- PHP删除目录/文件夹的三种方法 2012/05/18
- PHP中的内存管理问题详解 2012/05/18
- php+fastcgi出现No input file specified.错误解决方法 2012/05/17
- PHP企业级应用之常见缓存技术篇 2012/05/17
- PHP站点安全配置 2012/05/17
- PHP企业级应用之WebService续篇 2012/05/17
- PHP企业级应用之WebService篇 2012/05/17