How to determine Chinese and English characters in php_PHP tutorial

WBOY
Release: 2016-07-13 10:22:34
Original
1228 people have browsed it

How to judge Chinese and English characters in PHP

The basis for PHP to judge Chinese and English is the ASII value of the character, and the ASII value of the character is also different due to different encodings. In order to write a PHP program that determines Chinese and English characters, we must first understand the ASII value range of Chinese and English characters in each encoding:

1. GBK (GB2312/GB18030)
x00-xff GBK double-byte 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)





New Document


$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 "Enter correctly";
} else {
echo "Wrong input";
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/847207.htmlTechArticleHow to judge Chinese and English characters in PHP The basis for judging Chinese and English in PHP is the ASII value of the character, and the ASII value of the character It also varies depending on the encoding. In order to write a php program that determines Chinese and English characters,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template