Home > Backend Development > PHP Tutorial > php抓取中文字符

php抓取中文字符

WBOY
Release: 2016-06-23 13:29:40
Original
884 people have browsed it

抓取中文的来源可以是文本,网页,只要是有中文的地方就行,每个部分都有注释,里面包含中文的抓取和中文去重两部分。


 <?php $str = "ddddvvv(,中文.)dfdsfds字啊 啊符啊.";//把GB2312编码转化为 UTF-8编码//$str = mb_convert_encoding($str, 'UTF-8', 'GB2312');//正则匹配preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $str, $matches);//把匹配到的数组连接为字符串$str = implode('', $matches[0]);//中文字符去重$str = str_split($str,3);$str = array_unique($str);$str = implode($str);//把UTF-8编码转化为 GB2312编码$str = mb_convert_encoding($str, 'GB2312', 'UTF-8'); echo $str; ?>
Copy after login


版权声明:本文为博主原创文章,未经博主允许不得转载。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template