Home >Backend Development >PHP Tutorial >Simple code example of php regular expression matching Chinese characters

Simple code example of php regular expression matching Chinese characters

黄舟
黄舟Original
2017-03-28 14:53:561576browse

Simple code example of php regular expression matching Chinese characters

<?php
$str = &#39;i love you, 中国&#39;;
// $str = &#39;i love you, &#39;;
// if(preg_match(&#39;/[\x7f-\xff]/i&#39;,$str)) { //
if(preg_match(&#39;/[\x{4e00}-\x{9fa5}]+/u&#39;,$str)) { // 可以没有花括号, /[\x4e00-\x9fa5]+/u
	echo &#39;字符串中含有中文!&#39;;
} else {
	echo &#39;no&#39;;
}

Related articles:

How PHP uses regular expressions to match parentheses

Summary on the use of common PHP regular expression functions

Detailed explanation of what regular expressions are and their usage

The above is the detailed content of Simple code example of php regular expression matching Chinese characters. For more information, please follow other related articles on the PHP Chinese website!

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