How to determine Chinese and English characters in php
PHP judges Chinese and English based on the ASII value of the character, and the ASII value of the character varies with the encoding. To write a php program that can judge Chinese and English characters, we must first understand the ASII value range of Chinese and English characters under each encoding:
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)
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
</HEAD>
<BODY>
<?
$ Str = "Chinese ";
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 ";
}
?>
</BODY>
</HTML>