Why does \ w match non-English characters in Mac OS X PHP?

I found that "\ w" can match Chinese characters in my Mac OS X PHP environment. but the same code does not work on Linux.

php -r "echo preg_match('/^\w+$/','人1234', \$m).chr(10); var_dump(\$m);"

Mac OS X 11.11.3 with PHP 5.6.18 (cli), PHP 5.4.45 (cli) result

1
array(1) {
  [0] =>
  string(7) "人1234"
}

Cent OS 6 with PHP 5.6.18 (cli), PHP 5.2.17p1 (cli) result

0
array(0) {
}

The PHP manual says

The definition of letters and numbers is controlled by the PCRE character tables and may vary if language matching occurs. For example, in "fr" (French), for accented characters, some character codes greater than 128 are used, and they are matched by the \ w character. "

I think something is a reference to the PCRE library. Can anyone explain why?

+4
1

, , PCRE PHP:

pcre *pcre_compile(const char *pattern,
      int options,
      const char **errptr,
      int *erroffset,
      const unsigned char *tableptr); 

, RegExes , options , PCRE_UCP (UCP = Unicode Character Properties), \w, \d unicode, , PHP PCRE Mac OS X .

(*UCP), " ", PCRE PCRE_UCP, ​​ .

. /(*UCP)\w+/ . ( )

- PCRE:

PCRE , , - , , .

UTF-8 16- 32- 256. , , \w \d.

, PCRE Unicode, \p \P, , , PCRE_UCP ; \w , Unicode .

Unicode . 128, Unicode, , .

0

All Articles