php uses regular expressions to verify Chinese.
php uses preg_match to match and determine whether a string contains Chinese or is all Chinese. The method is as follows:
$str = 'php学习博客';
if(preg_match('/[\x7f-\xff]/', $str)){
echo '字符串中有中文<br/>';
}else{
echo '字符串中没有中文<br/>';
}
if(preg_match('/^[\x7f-\xff]+$/', $str)){
echo '字符串全是中文';
}else{
echo '字符串不全是中文';
}
Copy after login
The output result of the above program is:
There is Chinese in the string
The strings are not all in Chinese
It has been tested under utf-8 and gbk encoding, and both can be used.
Articles you may be interested in:
- Problems with PHP regular expression verification of Chinese
- A summary of the analysis of php regular expression matching Chinese problems
- php using regular expressions Detailed explanation of expression matching Chinese examples
- PHP regular expression to determine Chinese UTF-8 or GBK and specific implementation
- PHP regular expression to replace spaces, newlines, Chinese commas, etc. with English commas
- php regular expression separates alphanumeric and Chinese characters in a string
- Using regular expressions to extract Chinese implementation notes in PHP
- Correct PHP matching UTF-8 Chinese regular expression Expression
http://www.bkjia.com/PHPjc/1120005.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1120005.htmlTechArticlephp uses regular expressions to verify Chinese, php uses preg_match to match and determine whether a string contains Chinese or is all Chinese The method is as follows: $str = 'php learning blog';if(preg_match('/[...