php获取中文首字母

汉字、英文、数字均适用。

PHP代码
  1. function getfirstchar($s0){   
  2. $s=iconv("UTF-8","gb2312"$s0);   
  3. $asc=ord($s{0})*256+ord($s{1})-65536;   
  4. if($asc>=-20319 and $asc<=-20284)return "A";   
  5. if($asc>=-20283 and $asc<=-19776)return "B";  
  6. if($asc>=-19775 and $asc<=-19219)return "C";   
  7. if($asc>=-19218 and $asc<=-18711)return "D";   
  8. if($asc>=-18710 and $asc<=-18527)return "E";   
  9. if($asc>=-18526 and $asc<=-18240)return "F";   
  10. if($asc>=-18239 and $asc<=-17923)return "G";   
  11. if($asc>=-17922 and $asc<=-17418)return "H";   
  12. if($asc>=-17417 and $asc<=-16475)return "J";   
  13. if($asc>=-16474 and $asc<=-16213)return "K";   
  14. if($asc>=-16212 and $asc<=-15641)return "L";   
  15. if($asc>=-15640 and $asc<=-15166)return "M";   
  16. if($asc>=-15165 and $asc<=-14923)return "N";   
  17. if($asc>=-14922 and $asc<=-14915)return "O";   
  18. if($asc>=-14914 and $asc<=-14631)return "P";   
  19. if($asc>=-14630 and $asc<=-14150)return "Q";   
  20. if($asc>=-14149 and $asc<=-14091)return "R";   
  21. if($asc>=-14090 and $asc<=-13319)return "S";   
  22. if($asc>=-13318 and $asc<=-12839)return "T";   
  23. if($asc>=-12838 and $asc<=-12557)return "W";   
  24. if($asc>=-12556 and $asc<=-11848)return "X";   
  25. if($asc>=-11847 and $asc<=-11056)return "Y";   
  26. if($asc>=-11055 and $asc<=-10247)return "Z";   
  27. return false;   
  28. }   


[本日志由 admin 于 2012-10-14 00:00 AM 更新]
上一篇: php 汉字转化成 二进制 十进制 十六进制 数字
下一篇: php 验证码【倾斜,正弦干扰线,黏贴,旋转】
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: php
相关日志:
评论: 0 | 引用: 0 | 查看次数: 1945
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭

 广告位

↑返回顶部↑