Home  >  Article  >  Backend Development  >  PHP regular expression matches Chinese characters_PHP tutorial

PHP regular expression matches Chinese characters_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:54:381862browse

The article tells you how to use php regular expressions to match Chinese characters. Below we will mainly talk about using preg_match mb_eregi to verify Chinese characters and solve problems in the regularization process.

The article tells you how to use PHP tutorials to match Chinese characters with regular expressions. Below we mainly talk about using preg_match mb_eregi to verify Chinese characters, and how to solve problems in the regularization process.

preg_match("/[a-z]{3,14}/",$content,[optional]$a); This returns a Boolean value, $a gets an array, and the matched characters are stored in $a ;


Regular Chinese characters

echo (mb_eregi("[x80-xff].","中文") ? "有" : "无") ."汉字";
echo (mb_eregi("^([x80-xff].)+$","Chinese") ? "All Chinese characters" : "");

Look at the function to determine all Chinese strings

$str = "How to match eregi in php with Chinese characters";
if (preg_match("/^[".chr(0x80)."-".chr(0xff)."]+$/",$str)) {
echo "This is a pure Chinese string";
} else{
echo "This is not a pure Chinese string";
}

preg_match_all($pat,……) and preg_replace($pat,……)……

preg_match_all("/(汉字)+/ism","I am a Chinese character, let’s see what you do to me!",$m_a);


If you know the beginning and end of the high and low bits of each code, then you can naturally write the regular expression, and it is directly sixteen bits. What is the difficulty? hehe. But please note that in php, x is used to indicate sixteen digits.

So as above, we can also use this regular expression to determine whether it is a Chinese character of gb2312

$str = "Little boy";
if(preg_match("/^[xb0-xf7][xa0-xfe]+$/",$str)){
print($str."It is indeed all Chinese characters");
} else {
print($str."This real tc is not all Chinese characters");
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631730.htmlTechArticleThe article tells you how to use php regular expressions to match Chinese characters. Below we mainly talk about using preg_match mb_eregi to verify Chinese characters. , and solutions to problems arising from the regular process. ...
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