This article mainly introduced the PHP and JavaScript regular match Chinese method, combined with the instance form analysis PHP, JavaScript regular matching Chinese operation skill for utf-8 and GBK encoding case, the need friend can refer to the following
This example describes how PHP and JavaScript are matched in Chinese. Share to everyone for your reference, as follows:
PHP is matched utf-8 Chinese: (emphasis is: [\x{4e00}-\x{9fa5}]+
)
$str = "Topic.alibabacloud.com", if (Preg_match ("/^[\x{4e00}-\x{9fa5}]+$/u", $str, $arr)) { print ("The string is all Chinese"); Echo ' <pre> '; Print_r ($arr);} else { print ("The string is not all Chinese"); Echo ' <pre> '; Print_r ($arr);}
PHP matches GBK, gb2312 Chinese:
Preg_match ("/^[". Chr (0XA1). " -". Chr (0xff)." +$/", $STR)
JavaScript regular matches Chinese:
var str = "PHP Programming", if (/^[\u4e00-\u9fa5]+$/.test (str)) {alert ("The string is all Chinese"),} else {alert ("The string is not all Chinese");}