Simple code example of php regular expression matching Chinese characters

黄舟
Release: 2023-03-06 16:24:02
Original
1558 people have browsed it

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;;
}
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!