Php Regular Expression matching Chinese characters-PHP source code

Source: Internet
Author: User
Tags php regular expression
Ec (2); php tutorial match Chinese Character regular expression match Chinese Character Regular Expression: [u4e00-u9fa5] Comment: Match Chinese character is really a headache, with this expression, it is easy to match double byte characters (including Chinese characters): [^ x00-xff] Comment: can be used to calculate the length of a string (a double byte length 2, ascii characters 1) * & nbsp; $ str & quot; singlepoint Single Point log & quot; script ec (2); script

Regular Expression matching Chinese characters in the php tutorial

Regular Expression matching Chinese characters: [u4e00-u9fa5]
Note: matching Chinese characters is really a headache. It is easy to use this expression.
Match double byte characters (including Chinese characters): [^ x00-xff]
Comment: it can be used to calculate the length of a string (a dual-byte length Meter 2, ascii character meter 1)
*/

$ Str = "singlepoint Single Point log ";
If (preg_match ("/^ [x {4e00}-x {9fa5}] + $/u", $ str )){
Print ("all strings are Chinese ");
} Else {
Print ("Not all strings are Chinese ");
}


$ Alias_len = mb_strlen ($ value ['Alias'], "UTF-8 ");
$ Temp_array = array ();
For ($ I = 0; $ I <$ alias_len; $ I ++)
{
$ Temp_array [$ I] = mb_substr ($ value ['Alias'], $ I, 1, "UTF-8 ");
If (ord (substr ($ temp_array [$ I], 0, 1)> '0xe0' & strlen ($ temp_array [$ I]) <3)
$ Temp_array [$ I] = '';

}
$ Value ['Alias'] = implode ('', $ temp_array );

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.