Pcre of different versions of PHP in UTF8 coding problem

Source: Internet
Author: User
Platform:
System version: OS X Yosemite 10.10.1
Kernel version: Darwin 14.0.0

PHP code (the encoding of the file is UTF-8)

$str = '自此直至2010年n'; preg_match_all('/(\w+)/u', $str, $matches);print_r($matches[0]);

PHP 5.5.14 (mac Default)
PCRE Edition: PCRE Library version 8.02 2010-03-19
Output:

Array(    [0] => 2010    [1] => n)

PHP 5.4.36 (Brew installation)
PCRE Edition: PCRE Library version 8.32 2012-11-30
Output:

Array(    [0] => 自此直至2010年n)

May I ask how the differences between the 2 versions are avoided?

Reply content:

Platform:
System version: OS X Yosemite 10.10.1
Kernel version: Darwin 14.0.0

PHP code (the encoding of the file is UTF-8)

$str = '自此直至2010年n'; preg_match_all('/(\w+)/u', $str, $matches);print_r($matches[0]);

PHP 5.5.14 (mac Default)
PCRE Edition: PCRE Library version 8.02 2010-03-19
Output:

Array(    [0] => 2010    [1] => n)

PHP 5.4.36 (Brew installation)
PCRE Edition: PCRE Library version 8.32 2012-11-30
Output:

Array(    [0] => 自此直至2010年n)

May I ask how the differences between the 2 versions are avoided?

ujust get rid of the modifier, demo:http://3v4l.org/c0469.

U (PCRE_UTF8)

This modifier opens an additional feature that is incompatible with Perl. The pattern string is considered to be utf-8. This modifier is available from the UNIX version of PHP 4.1.0 or higher, Win32 version of PHP 4.2.3. PHP 4.3.5 starts checking the utf-8 legitimacy of the pattern.
-Pattern modifiers

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