Home > php教程 > php手册 > body text

如何用正则表达式来表示中文?

WBOY
Release: 2016-06-21 09:05:16
Original
1261 people have browsed it

正则|中文

由于中文的ASCII码是有一定的范围的。所以你可以用下面的正则表达式来表示中文。

/^[chr(0xa1)-chr(0xff)]+$/

下面是一个使用的例子:

$str = "超越PHP";
if  (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) {
    echo "这是一个纯中文字符串";
} else {
    echo "这不是一个纯中文字串";
}



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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template