search
Homephp教程php手册php 判断中英文字符

php 判断中英文字符

Jun 13, 2016 am 09:55 AM
gbkphpjudgmentpaircharacterbytecodingscope

编码表

双字节字符编码范围

1. gbk (gb2312/gb18030)
x00-xff gbk双字节编码范围
x20-x7f ascii
xa1-xff 中文 gb2312
x80-xff 中文 gbk

2. utf-8 (unicode)

u4e00-u9fa5 (中文)
x3130-x318f (韩文
xac00-xd7a3 (韩文)
u0800-u4e00 (日文)


$str = "中国";
echo $str;
echo "
";

//if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) { //只能在gb2312情况下使用 
if (preg_match("/^[x7f-xff]+$/", $str)) { //兼容gb2312,utf-8
    echo "正确输入";
} else {
    echo "错误输入";
}
?>

中文判断问题,其实有很多学问,底层的内部编码,涉及utf-8,gbk,gb13800的各种不同。曾经研究过如何区分一个字符是什么字符的问题。关联细节太多。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools