php实现过滤掉非汉字字符只保留中文字符 这篇文章主要介绍了php实现过滤掉非汉字字符只保留中文字符,本文直接给出实现代码,需要的朋友可以参考下
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
utf-8
$str = mb_convert_encoding($str, 'utf-8', 'gb2312');
preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $str, $matches);
$str = join('', $matches[0]);
//转换 utf-8 -> gb2312
$str = mb_convert_encoding($str, 'gb2312', 'utf-8');
echo $str; //输出 中文字符
?>
http://www.bkjia.com/phpjc/1011118.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1011118.htmltecharticlephp实现过滤掉非汉字字符只保留中文字符 这篇文章主要介绍了php实现过滤掉非汉字字符只保留中文字符,本文直接给出实现代码,需要的朋友...