Chinese character judgment is based on string encoding, /^[chr(0xa1)-chr(0xff)]+$ This is the PHP verification regular expression to judge whether it is Chinese Let’s look at an example of verifying Chinese characters
Chinese character judgment is based on string encoding, /^[chr(0xa1)-chr(0xff)]+$ This is the PHP tutorial verification regular expression to judge whether it is Chinese
Let’s look at an example of verifying Chinese
$str = "Yiju Tutorial Network";
if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) {
echo "This is a pure Chinese string";
} else {
echo "This is not a pure Chinese string";
}
js
var str = "php programming";
if (/^[u4e00-u9fa5]+$/.test(str)) {
alert("The string is all in Chinese");
} else {
alert("This string is not all in Chinese");
}php
if($en_utf8)
{ $joid = preg_replace("[^0-9a-za-z_-|x4e00-x9fa5|:|/|#|.]","",$joid); > else
{ $joid = preg_replace("[^0-9a-za-z_-|".chr(0xa1)."-".chr(0xff)."|:|/|#|.]","",$ joid); } //Chinese matching of gb2312
To determine whether a string is Chinese in php, you will follow this idea: