判断是否有中文。
if (preg_match("/[x7f-xff]/", $string)) { echo "true"; }else{ echo "false"; }
判断是否全部是中文
if (preg_match("/^[x7f-xff]+$/", $str)) {
//兼容gb2312,utf-8 echo "true";
} else {
echo "false";
}
判断中文和编码有关 gbk是双字节,utf8是三字节,可以根据中文的范围来判断
编码范围1. GBK (GB2312/GB18030)
/x00-/xff GBK双字节编码范围
/x20-/x7f ASCII
/xa1-/xff 中文
/x80-/xff 中文
2. UTF-8 (Unicode)
/一-/龥 (中文)
/x3130-/x318F (韩文
/xAC00-/xD7A3 (韩文)
/u0800-/一 (日文)
ps: 韩文是大于[/龥]的字符
正则例子:
preg_replace(”/([/x80-/xff])/”,””,$str);
preg_replace(”/([一-龥])/”,””,$str);
JS 验证中文:
function isChinaOrLett(s){//判断是否是汉字、字母组成 var regu = "^[a-zA-Z一-龥]+$"; var re = new RegExp(regu); if (re.test(s)) { alert(s); }else{ alert("f"); } }
if (preg_match("/[x7f-xff]/", $string)) { echo "true"; }else{ echo "false"; }
判断是否全部是中文
if (preg_match("/^[x7f-xff]+$/", $str)) {
//兼容gb2312,utf-8 echo "true";
} else {
echo "false";
}
判断中文和编码有关 gbk是双字节,utf8是三字节,可以根据中文的范围来判断
编码范围1. GBK (GB2312/GB18030)
/x00-/xff GBK双字节编码范围
/x20-/x7f ASCII
/xa1-/xff 中文
/x80-/xff 中文
2. UTF-8 (Unicode)
/一-/龥 (中文)
/x3130-/x318F (韩文
/xAC00-/xD7A3 (韩文)
/u0800-/一 (日文)
ps: 韩文是大于[/龥]的字符
正则例子:
preg_replace(”/([/x80-/xff])/”,””,$str);
preg_replace(”/([一-龥])/”,””,$str);
JS 验证中文:
function isChinaOrLett(s){//判断是否是汉字、字母组成 var regu = "^[a-zA-Z一-龥]+$"; var re = new RegExp(regu); if (re.test(s)) { alert(s); }else{ alert("f"); } }
67朵
1个