PHP Crawl Chinese characters

Source: Internet
Author: User

The source of crawling Chinese can be text, Web pages, as long as there is a Chinese place on the line, each part has a comment, which contains Chinese crawling and Chinese to heavy two parts.


<?php$str = "DDDDVVV (, Chinese.) Dfdsfds words, ah, ah. "; /convert GB2312 encoding to UTF-8 code//$str = mb_convert_encoding ($str, ' UTF-8 ', ' GB2312 ');//Regular Match preg_match_all ('/[\x{4e00}-\x{9fff }]+/u ', $str, $matches);//Connect the matched array to a string $str = Implode (", $matches [0]);//Chinese character de-weight $str = Str_split ($str, 3); $str = Array_ Unique ($STR); $str = implode ($STR);//convert UTF-8 code to GB2312 encoding $str = mb_convert_encoding ($str, ' GB2312 ', ' UTF-8 '); echo $str;?>


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

PHP Crawl Chinese characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.