Php regular expression matching Chinese characters _ PHP Tutorial

Source: Internet
Author: User
Php regular expressions match Chinese characters. The article tells you how to use php regular expressions to match Chinese characters. The following describes how to use preg_matchmb_eregi to verify Chinese characters and solve problems in the regular expression process. The article tells you how to use php regular expressions to match Chinese characters. The following describes how to use preg_match mb_eregi to verify Chinese characters and solve problems in the regular expression process.

The article tells you how to use the regular expression in the php Tutorial to match Chinese characters. The following describes how to use preg_match mb_eregi to verify Chinese characters and solve problems in the regular expression process.

Preg_match ("/[a-z] {3, 14}/", $ content, [optional] $ a); this returns a boolean value, $ a returns an array, protect the matched characters against $;


Regular Chinese characters

Echo (mb_eregi ("[x80-xff].", "medium d ")? "Yes": "No"). "Chinese characters ";
Echo (mb_eregi ("^ ([x80-xff].) + $", "Chinese ")? "All Chinese characters ":"");

Let's take a look at all Chinese string functions.

$ Str = "how does php eregi match Chinese characters ";
If (preg_match ("/^ [". chr (0x80). "-". chr (0xff). "] + $/", $ str )){
Echo "this is a pure Chinese string ";
} Else {
Echo "this is not a pure Chinese string ";
}

Preg_match_all ($ pat ,......) And preg_replace ($ pat ,......)......

Preg_match_all ("/(Chinese characters) +/ism", "I am a Chinese character, see what you think of me! ", $ M_a );


After the beginning and end of each encoding's high and low levels, you can naturally write regular expressions and directly use sixteen digits. What are the difficulties? Haha. Note that in php, the sixteen bits use x.

Therefore, we can use this regular expression to determine whether it is a gb2312 Chinese character.

$ Str = "example ";
If (preg_match ("/^ [xb0-xf7] [xa0-xfe] + $/", $ str )){
Print ($ str. "all Chinese characters are true ");
} Else {
Print ($ str. "this tc is not all Chinese characters ");
}
?>

The regular expression matches Chinese characters. The following describes how to use preg_match mb_eregi to verify Chinese characters and solve problems in the regular expression process ....

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.