Home  >  Article  >  Backend Development  >  MySQL traverses the string and determines whether the string is all Chinese or contains Chinese implementation code in PHP

MySQL traverses the string and determines whether the string is all Chinese or contains Chinese implementation code in PHP

WBOY
WBOYOriginal
2016-07-29 08:46:461192browse

1. The judgment is all in Chinese

Copy the code The code is as follows:


$str="'324 is";
if(!eregi("[^x80-xff]","$str")) {
echo "all in Chinese";
}else{
echo "not";
}


Second, judge that it contains Chinese

Copy the code The code is as follows:


$str = "Chinese";
if (preg_match("/[x7f-xff]/", $str)) {
echo "Contains Chinese";
}else{
echo "No Chinese";
}
or
$pattern = '/[^ x00-x80]/';
if(preg_match($pattern,$str)){
echo "Contains Chinese";
}else{
echo "No Chinese";
}


My methods are all Tested under utf-8, not tested under other encodings.

The above introduces the implementation code of mySQL traversing strings in PHP to determine whether a string is all Chinese or contains Chinese characters, including the content of mySQL traversing strings. I hope it will be helpful to friends who are interested in PHP tutorials.

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