php中文正则UTF-8和GBK
$str=’中国’;
$utf=”;//编码为UTF-8时为真//前为UTF-8后为GBK
$preg=$utf ? ‘/^[\x{4e00}-\x{9fa5}]+$/u’ : "/^[".chr(0xa1)."-".chr(0xff)."]+$/";if(preg_match($preg,$str)){
echo ‘all chinese’;
}else {
echo ‘not all chinese’;
}
原创文章如转载,请注明:转载自火跃
本文网址:http://www.huoyue.org/php-chinese-preg
没有评论▼