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