Home > Backend Development > PHP Tutorial > PHP uses regular expressions to verify Chinese, _PHP tutorial

PHP uses regular expressions to verify Chinese, _PHP tutorial

WBOY
Release: 2016-07-12 08:54:17
Original
923 people have browsed it

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

www.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('/[...
Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template