Php Chinese character string first letter acquisition function sharing
Source: Internet
Author: User
This article describes how to obtain the first letter of a Chinese character string in php. if you need it, refer to it.
The code is as follows:
Function chineseFirst ($ str)
{
$ Str = iconv ("UTF-8", "gb2312", $ str); // if the program is gbk, comment out this line
// Judge whether all strings are Chinese
If (preg_match ("/^ [\ x7f-\ xff]/", $ str ))
{
$ Fchar = ord ($ str {0 });
If ($ fchar> = ord ("A") and $ fchar <= ord ("z") return strtoupper ($ str {0 });
$ A = $ str;
$ Val = ord ($ a {0}) * 256 + ord ($ a {1})-65536;
If ($ val >=- 20319 and $ val <=-20284) return "";
If ($ val >=- 20283 and $ val <=-19776) return "B ";
If ($ val >=- 19775 and $ val <=-19219) return "C ";
If ($ val >=- 19218 and $ val <=-18711) return "D ";
If ($ val >=- 18710 and $ val <=-18527) return "E ";
If ($ val >=- 18526 and $ val <=-18240) return "F ";
If ($ val >=- 18239 and $ val <=-17923) return "G ";
If ($ val >=- 17922 and $ val <=-17418) return "H ";
If ($ val >=- 17417 and $ val <=-16475) return "J ";
If ($ val >=- 16474 and $ val <=-16213) return "K ";
If ($ val >=- 16212 and $ val <=-15641) return "L ";
If ($ val >=- 15640 and $ val <=-15166) return "M ";
If ($ val >=- 15165 and $ val <=-14923) return "N ";
If ($ val >=- 14922 and $ val <=-14915) return "O ";
If ($ val >=- 14914 and $ val <=-14631) return "P ";
If ($ val >=- 14630 and $ val <=-14150) return "Q ";
If ($ val >=- 14149 and $ val <=-14091) return "R ";
If ($ val >=- 14090 and $ val <=-13319) return "S ";
If ($ val >=- 13318 and $ val <=-12839) return "T ";
If ($ val >=- 12838 and $ val <=-12557) return "W ";
If ($ val >=- 12556 and $ val <=-11848) return "X ";
If ($ val >=- 11847 and $ val <=-11056) return "Y ";
If ($ val >=- 11055 and $ val <=-10247) return "Z ";
} Else
{
Return false;
}
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.