Home > Backend Development > PHP Tutorial > PHP batch obtains the codes of initial letters (Chinese characters, numbers, English)

PHP batch obtains the codes of initial letters (Chinese characters, numbers, English)

WBOY
Release: 2016-07-25 09:03:40
Original
811 people have browsed it
  1. $mysql_server_name='127.0.0.1'; //Change to your own mysql database server

  2. $mysql_username='user'; //Change to your own mysql database user Name
  3. $mysql_password='password'; //Change to your own mysql database password
  4. $mysql_database='database'; //Change to your own mysql database name
  5. mysql_connect('127.0.0.1', $mysql_username,$mysql_password) or die('database not access');
  6. mysql_select_db($mysql_database);
  7. mysql_query("SET NAMES 'utf8'");
  8. $equery2 = " select title from table 1 ";
  9. $result2=mysql_query($equery2) ;

  10. while ($row = mysql_fetch_array($result2, MYSQL_BOTH))

  11. {
  12. $title=$row["title"];
  13. if (ord($title)>128) { //Start with Chinese characters
  14. echo $letter=getfirstchar($title);
  15. }else if(ord($title)>=48 and ord($title)<=57){ //Start with numbers
  16. echo $letter =iconv_substr($title,0,1,'utf-8');
  17. }else if(ord($title)>=65 and ord($title)<=90){ //Capital English beginning
  18. echo $letter=iconv_substr($title,0,1,'utf-8');
  19. }else if(ord($title)>=97 and ord($title)<=122){ //Lowercase English starts
  20. echo $letter=iconv_substr($title,0,1,'utf-8');
  21. }
  22. }

  23. function getfirstchar($s0){

  24. $s=iconv("UTF -8","gb2312", $s0);
  25. $asc=ord($s{0})*256+ord($s伊雪)-65536;
  26. if($asc>=-20319 and $asc< =-20284)return "A";
  27. if($asc>=-20283 and $asc<=-19776)return "B";
  28. if($asc>=-19775 and $asc<=-19219)return " C";
  29. if($asc>=-19218 and $asc<=-18711)return "D";
  30. if($asc>=-18710 and $asc<=-18527)return "E";
  31. if( $asc>=-18526 and $asc<=-18240)return "F";
  32. if($asc>=-18239 and $asc<=-17923)return "G";
  33. if($asc>=-17922 and $asc<=-17418)return "H";
  34. if($asc>=-17417 and $asc<=-16475)return "J";
  35. if($asc>=-16474 and $asc<=- 16213)return "K";
  36. if($asc>=-16212 and $asc<=-15641)return "L";
  37. if($asc>=-15640 and $asc<=-15166)return "M" ;
  38. if($asc>=-15165 and $asc<=-14923)return "N";
  39. if($asc>=-14922 and $asc<=-14915)return "O";
  40. if($asc> ;=-14914 and $asc<=-14631)return "P";
  41. if($asc>=-14630 and $asc<=-14150)return "Q";
  42. if($asc>=-14149 and $ asc<=-14091)return "R";
  43. if($asc>=-14090 and $asc<=-13319)return "S";
  44. if($asc>=-13318 and $asc<=-12839) return "T";
  45. if($asc>=-12838 and $asc<=-12557)return "W";
  46. if($asc>=-12556 and $asc<=-11848)return "X";
  47. if($asc>=-11847 and $asc<=-11056)return "Y";
  48. if($asc>=-11055 and $asc<=-10247)return "Z";
  49. return false;
  50. }
  51. ?>

Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template