PHP determines if the string contains Chinese

Source: Internet
Author: User
Refer:http://www.wilf.cn/post/php-match-chinese-str.html

Since having a black hat seo, dealing with spam (spam) has been one of the job content of the site staff. The persecution of our not spam message group machine, is the garbage user registration machine.

Judging whether the string contains Chinese is one way to deal with spam, can effectively block the pure English spam, you can also use this method to standardize user registration. Look at the code below, compatible with gb2312 and Utf-8.

!--? $str =" Test Chinese ", Echo $str, echo" ",//if (Preg_match ("/^[". Chr (0XA1)." -". Chr (0xff)." and #43, $/", $str)) {//can only be used in GB2312 case//if (Preg_match ("/^[\x7f-\xff]& #43; $/", $str)) {//compatible GB2312,UTF-8//Determine if the string is all Chinese if ( Preg_match ("/[\x7f-\xff]/", $str)) {//Determine if there is a Chinese echo "correct input" in the string;} else {echo "error input";}? -->

, double-byte character encoding range

1. GBK (gb2312/gb18030)
\x00-\xff GBK Double-byte encoding range
\x20-\x7f ASCII
\xa1-\xff Chinese gb2312
\x80-\xff Chinese GBK

2. UTF-8 (Unicode)
\u4e00-\u9fa5 (Chinese)
\x3130-\x318f (Korean
\xac00-\xd7a3 (Korean)
\u0800-\u4e00 (Japanese) */


The above describes the PHP judgment string contains Chinese, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.