Home > Backend Development > PHP Tutorial > Implementation code to determine whether a string is all Chinese or contains Chinese in PHP_PHP Tutorial

Implementation code to determine whether a string is all Chinese or contains Chinese in PHP_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:24:40
Original
865 people have browsed it

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, determine whether 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";
}

I tested these methods under utf-8 and have not tested them under other encodings.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324230.htmlTechArticleFirst, judge that all the copied codes are in Chinese: $str="'324 is"; if(!eregi ("[^x80-xff]","$str")){ echo "all in Chinese"; }else{ echo "not"; } Second, judge that it contains Chinese copy code...
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template