PHP and JavaScript match the Chinese method to implement the detailed

Source: Internet
Author: User
Tags php programming
This article mainly introduced the PHP and JavaScript regular match Chinese method, combined with the instance form analysis PHP, JavaScript regular matching Chinese operation skill for utf-8 and GBK encoding case, the need friend can refer to the following

This example describes how PHP and JavaScript are matched in Chinese. Share to everyone for your reference, as follows:

PHP is matched utf-8 Chinese: (emphasis is: [\x{4e00}-\x{9fa5}]+ )

$str = "Topic.alibabacloud.com", if (Preg_match ("/^[\x{4e00}-\x{9fa5}]+$/u", $str, $arr)) {  print ("The string is all Chinese");  Echo ' <pre> ';  Print_r ($arr);} else {  print ("The string is not all Chinese");  Echo ' <pre> ';  Print_r ($arr);}

PHP matches GBK, gb2312 Chinese:

Preg_match ("/^[". Chr (0XA1). " -". Chr (0xff)." +$/", $STR)

JavaScript regular matches Chinese:

var str = "PHP Programming", if (/^[\u4e00-\u9fa5]+$/.test (str)) {alert ("The string is all Chinese"),} else {alert ("The string is not all Chinese");}

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.