PHP implementation to get the first letter in Chinese and English _ PHP Tutorial

Source: Internet
Author: User
PHP is used to obtain the first letter in Chinese and English. PHP is used to obtain the first letter in Chinese and English. This article is a simple method and example of extracting the first letter in Chinese and English characters using php. it is very useful. if you need it, you can use PHP to obtain the first letter in Chinese and English.

This article will share with you how to use php to extract the first letter of Chinese and English characters.

PHP to obtain the first letter in Chinese and English

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

/**

*

*/

Function getfirstchar ($ s0 ){

If ($ s0 [0] = 'I' | $ s [0] = 'I '){

Return "I ";

} Elseif ($ s0 [0] = 'U' | $ s [0] = 'u '){

Return 'u ';

} Elseif ($ s0 [0] = 'V' | $ s [0] = 'V '){

Return 'V ';

} Else {

$ 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 "H ";

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;

}

}

The above is all the content of this article. I hope you will like it.

This article will share with you the method and example of extracting the first letter of Chinese and English characters in php. it is very useful and can be used by a small partner...

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.