PHP correct match UTF-8 Chinese regular _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP matches the regular expression of UTF-8 Chinese correctly. Go directly to code 1? Php2 $ string hello, helloworld; 3preg_match (~ [X {4e00}-x {9fa5}] + ~ U, $ string, $ array); 456print_r ($ array); print the result: 1Array2 (3 [0] Hello, go directly to the code.
1 2 $ string = "hello, hello world ";
3 preg_match ('~ [\ X {4e00}-\ x {9fa5}] ++ ~ U', $ string, $ array );
4
5
6 print_r ($ array );
Print result:
1 Array
2 (
3 [0] => Hello
4)
Note: encoding is UTF-8 Oh GBK is not written in this way.
Author: yangqijun

Limit 1? Php 2 $ string = hello, hello world; 3preg_match (~ [\ X {4e00}-\ x {9fa5}] ++ ~ U, $ string, $ array); 4 5 6print_r ($ array); print the result: 1 Array 2 (3 [0] = hello...

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.