How to determine Chinese and English characters in php

Source: Internet
Author: User

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>

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.