[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+
PHP中GBK和UTF8编码处理
一、编码范围
1. GBK (GB2312/GB18030)
/x00-/xff
/x20-/x7f
/xa1-/xff
/x80-/xff
2. UTF-8 (Unicode)
/u4e00-/u9fa5 (中文)
/x3130-/x318F (韩文
/xAC00-/xD7A3 (韩文)
/u0800-/u4e00 (日文)
ps: 韩文是大于[/u9fa5]的字符
正则例子:
preg_replace("/([/x80-/xff])/","",$str);
preg_replace("/([u4e00-u9fa5])/","",$str);
二、代码例子
//判断内容里有没有中文-GBK (PHP)
function check_is_chinese($s){
}
//获取字符串长度-GBK (PHP)
function gb_strlen($str){
}
//截取字符串字串-GBK (PHP)
function gb_substr($str, $len){
}
//统计字符串长度-UTF8 (PHP)
function utf8_strlen($str) {
}
//截取字符串-UTF8(PHP)
function utf8_substr($str,$position,$length){
}
//字符串长度统计-UTF8 [中文3个字节,俄文、韩文占2个字节,字母占1个字节] (Ruby)
def utf8_string_length(str)
}
//判断是否是有韩文-UTF-8 (JavaScript)
function checkKoreaChar(str) {
}
//判断是否有中文字符-GBK (JavaScript)
function check_chinese_char(s){
三、参考文档
另:
public function csubstr($str, $start=0, $length, $charset="utf-8",$suffix=true)
{
if(function_exists("mb_substr"))
return mb_substr($str, $start, $length, $charset);
$re['utf-8'] ="/[/x01-/x7f]|[/xc2-/xdf][/x80-/xbf]|[/xe0-/xef][/x80-/xbf]{2}|[/xf0-/xff][/x80-/xbf]{3}/";
$re['gb2312'] = "/[/x01-/x7f]|[/xb0-/xf7][/xa0-/xfe]/";
$re['gbk'] = "/[/x01-/x7f]|[/x81-/xfe][/x40-/xfe]/";
$re['big5'] ="/[/x01-/x7f]|[/x81-/xfe]([/x40-/x7e]|/xa1-/xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("",array_slice($match[0], $start, $length));
if($suffix) return $slice."…";
return $slice;
}