Home  >  Article  >  Backend Development  >  How to use regular expressions to represent Chinese?

How to use regular expressions to represent Chinese?

巴扎黑
巴扎黑Original
2016-11-30 11:06:532037browse

Because the Chinese ASCII code has a certain range. So you can use the following regular expression to represent Chinese.

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

Here is an example of usage:

$str = "Beyond PHP";
if (preg_match("/^[".chr( 0xa1)."-".chr(0xff)."]+$/", $str)) {
echo "This is a pure Chinese string";
} else {
echo "This is not a pure Chinese string ";
}


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