PHPIN.NET

 找回密码
 立即注册
查看: 6828|回复: 0

[高级进阶] PHP获取信息首字母函数

[复制链接]

469

主题

31

回帖

5569

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5569
发表于 2014-3-29 16:47:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
PHP获取信息首字母函数:
  1. function getfirstchar($s0){
  2. $fchar = ord($s0{0});
  3. if($fchar >= ord("A") and $fchar <= ord("z"))return strtoupper($s0{0});
  4. $s1 = iconv("UTF-8","gb2312", $s0);
  5. $s2 = iconv("gb2312","UTF-8", $s1);
  6. if($s2 == $s0){$s = $s1;}else{$s = $s0;}
  7. $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
  8. if($asc >= -20319 and $asc <= -20284) return "A";
  9. if($asc >= -20283 and $asc <= -19776) return "B";
  10. if($asc >= -19775 and $asc <= -19219) return "C";
  11. if($asc >= -19218 and $asc <= -18711) return "D";
  12. if($asc >= -18710 and $asc <= -18527) return "E";
  13. if($asc >= -18526 and $asc <= -18240) return "F";
  14. if($asc >= -18239 and $asc <= -17923) return "G";
  15. if($asc >= -17922 and $asc <= -17418) return "I";
  16. if($asc >= -17417 and $asc <= -16475) return "J";
  17. if($asc >= -16474 and $asc <= -16213) return "K";
  18. if($asc >= -16212 and $asc <= -15641) return "L";
  19. if($asc >= -15640 and $asc <= -15166) return "M";
  20. if($asc >= -15165 and $asc <= -14923) return "N";
  21. if($asc >= -14922 and $asc <= -14915) return "O";
  22. if($asc >= -14914 and $asc <= -14631) return "P";
  23. if($asc >= -14630 and $asc <= -14150) return "Q";
  24. if($asc >= -14149 and $asc <= -14091) return "R";
  25. if($asc >= -14090 and $asc <= -13319) return "S";
  26. if($asc >= -13318 and $asc <= -12839) return "T";
  27. if($asc >= -12838 and $asc <= -12557) return "W";
  28. if($asc >= -12556 and $asc <= -11848) return "X";
  29. if($asc >= -11847 and $asc <= -11056) return "Y";
  30. if($asc >= -11055 and $asc <= -10247) return "Z";
  31. if(!trim($s0)){return null;}
  32. $s0=esub($s0,1);
  33. $numstrs='123456789一二三四五六七八九';
  34. $numstr['1']='1';
  35. $numstr['2']='2';
  36. $numstr['3']='3';
  37. $numstr['4']='4';
  38. $numstr['5']='5';
  39. $numstr['6']='6';
  40. $numstr['7']='7';
  41. $numstr['8']='8';
  42. $numstr['9']='9';
  43. $numstr['一']='1';
  44. $numstr['二']='2';
  45. $numstr['三']='3';
  46. $numstr['四']='4';
  47. $numstr['五']='5';
  48. $numstr['六']='6';
  49. $numstr['七']='7';
  50. $numstr['八']='8';
  51. $numstr['九']='9';
  52. if(strstr($numstrs,$s0)){
  53. return $numstr[$s0];
  54. }}
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|PHPIN.NET ( 冀ICP备12000898号-14 )|网站地图

GMT+8, 2024-11-21 21:31

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表