Php judges Chinese and English characters (another one)
It seems that I remember a previous, was written by myself, today this is online, from: http://www.cnblogs.com/zcy_soft/archive/2010/12/13/1904791.html
- /* There are a lot of questions about Chinese Judgment. the underlying internal encoding involves UTF-8, gbk, and gb13800. I have studied how to differentiate what a character is. There are too many associated details.
- Today, I made a php code to judge Chinese characters. I hope to help my friends who study Chinese judgment. */
- New Document
-
- $ Str = "China ";
- Echo $ str;
- Echo "";
- // If (preg_match ("/^ [". chr (0xa1 ). "-". chr (0xff ). "] + $/", $ str) {// can only be used in the case of GB2312
- If (preg_match ("/^ [\ x7f-\ xff] + $/", $ str) {// Compatible with gb2312, UTF-8
- Echo "correct input ";
- } Else {
- Echo "incorrect input ";
- }
- ?>
- /*
- Encoding table
- Double byte character encoding range
- 1. GBK (GB2312/GB18030)
- \ X00-\ xff GBK dubyte encoding range
- \ X20-\ x7f ASCII
- \ Xa1-\ xff Chinese gb2312
- \ X80-\ xff Chinese gbk
- 2. UTF-8 (Unicode)
- \ U4e00-\ u9fa5 (Chinese)
- \ X3130-\ x318F (Korean
- \ XAC00-\ xD7A3 (Korean)
- \ U0800-\ u4e00 (Japanese )*/
|