$ Str = "Yunqi Community 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 ("all strings are Chinese ");
} Else {
Alert ("Not all strings are Chinese ");
}
Php
If ($ en_utf8)
{$ Joid = preg_replace ("[^ 0-9a-za-z _-| x4e00-x9fa5 |: |/| # |.]", "", $ joid);} // UTF-8 Chinese match
Else
{$ Joid = preg_replace ("[^ 0-9a-za-z _-| ". chr (0xa1 ). "-". chr (0xff ). "|: |/| # |.] "," ", $ joid);} // gb2312 Chinese match
To determine whether a string is Chinese in php, we will follow this idea:
<? Php
$ Str = "php programming ";
If (preg_match ("/^ [u4e00-u9fa5] + $/", $ str )){
Print ("all strings are Chinese ");
} Else {
Print ("Not all strings are Chinese ");
}
?>