PHP retrieves the first Chinese Character

Source: Internet
Author: User

Function getfirstchar ($ S0 ){
$ Fchar = ord ($ S0 {0 });
If ($ fchar> = ord ("A") and $ fchar <= ord ("Z") return strtoupper ($ S0 {0 });
$ S1 = iconv ("UTF-8", "gb2312", $ S0 );
$ S2 = iconv ("gb2312", "UTF-8", $ S1 );
If ($ S2 = $ S0) {$ S = $ S1;} else {$ S = $ S0 ;}
$ ASC = ord ($ s {0}) * 256 + ord ($ s {1})-65536;
If ($ ASC >=- 20319 and $ ASC <=-20284) Return "";
If ($ ASC >=- 20283 and $ ASC <=-19776) Return "B ";
If ($ ASC >=- 19775 and $ ASC <=-19219) Return "C ";
If ($ ASC >=- 19218 and $ ASC <=-18711) Return "D ";
If ($ ASC >=- 18710 and $ ASC <=-18527) Return "E ";
If ($ ASC >=- 18526 and $ ASC <=-18240) Return "F ";
If ($ ASC >=- 18239 and $ ASC <=-17923) Return "G ";
If ($ ASC >=- 17922 and $ ASC <=-17418) Return "I ";
If ($ ASC >=- 17417 and $ ASC <=-16475) Return "J ";
If ($ ASC >=- 16474 and $ ASC <=-16213) Return "K ";
If ($ ASC >=- 16212 and $ ASC <=-15641) Return "L ";
If ($ ASC >=- 15640 and $ ASC <=-15166) Return "M ";
If ($ ASC >=- 15165 and $ ASC <=-14923) Return "N ";
If ($ ASC >=- 14922 and $ ASC <=-14915) Return "O ";
If ($ ASC >=- 14914 and $ ASC <=- 14631) Return "p ";
If ($ ASC >=- 14630 and $ ASC <=-14150) Return "Q ";
If ($ ASC >=- 14149 and $ ASC <=-14091) Return "R ";
If ($ ASC >=- 14090 and $ ASC <=-13319) Return "S ";
If ($ ASC >=- 13318 and $ ASC <=-12839) Return "T ";
If ($ ASC >=- 12838 and $ ASC <=-12557) Return "W ";
If ($ ASC >=- 12556 and $ ASC <=-11848) Return "X ";
If ($ ASC >=- 11847 and $ ASC <=-11056) Return "Y ";
If ($ ASC >=- 11055 and $ ASC <=- 10247) Return "Z ";
Return NULL;
}


Function pinyin1 ($ ZH)
{
$ Ret = "";
$ S1 = iconv ("UTF-8", "gb2312", $ ZH );
$ S2 = iconv ("gb2312", "UTF-8", $ S1 );
If ($ S2 = $ ZH) {$ ZH = $ S1 ;}
For ($ I = 0; $ I <strlen ($ ZH); $ I ++)
{
$ S1 = substr ($ ZH, $ I, 1 );
$ P = ord ($ S1 );
If ($ P> 160)
{
$ S2 = substr ($ ZH, $ I ++, 2 );
$ Ret. = getfirstchar ($ S2 );
}
Else
{
$ Ret. = $ S1;
}
}
Return $ ret;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.