Home >php教程 >php手册 >如何用正则表达式来表示中文?

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

WBOY
WBOYOriginal
2016-06-21 09:05:161294browse

正则|中文

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

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

下面是一个使用的例子:

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



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