How to match Chinese with regex

Contents

A sample of PHP regex code for matching Chinese.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php
$str= "中文";

$par = "\x80-\xff";
$par2= chr(0xa1).'-'.chr(0xff);
/*
*The both of $par and $par2 regx can works well. 
*/
if(preg_match("/^[$par2]*$/",$str)){
 echo "\$str is Chinese!";
}else{
 echo "\$str is not Chinese!";
}
?>

Related Content