什么是preg_match_all`u`标志依赖?

时间:2011-09-17 18:31:16

标签: php regex preg-match

我在PHP应用程序中有一些代码,当我尝试在生产服务器上使用它时返回null,但它在开发服务器上运行正常。这是代码行:

// use the regex unicode support to separate the UTF-8 characters into an array
preg_match_all( '/./us', $str, $match );

u标志依赖于什么?我在启用和禁用mb_string的情况下进行了测试,但似乎没有影响它。

我得到的错误是

preg_match_all: Compilation failed: unknown option bit(s) set at offset -1

更多信息

这是prodction服务器上的选项之一:

'--with-pcre-regex=/opt/pcre'

这里是pcre部分

Picture.png http://img829.imageshack.us/img829/8524/pictureke.png

我相信这是@Wesley所指的注释:

In  order  process  UTF-8 strings, you must build PCRE to include UTF-8
support in the code, and, in addition,  you  must  call  pcre_compile()
with  the  PCRE_UTF8  option  flag,  or the pattern must start with the
sequence (*UTF8). When either of these is the case,  both  the  pattern
and  any  subject  strings  that  are matched against it are treated as
UTF-8 strings instead of strings of 1-byte characters.

有关如何“构建PCRE以包含UTF-8”的任何链接或提示?

via

pcretest -C

的结果
PCRE version 6.6 06-Feb-2006
Compiled with
  UTF-8 support
  Unicode properties support
  Newline character is LF
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

2 个答案:

答案 0 :(得分:5)

此标志取决于在启用unicode支持的情况下构建的PCRE。

PHP捆绑了这个库,它通常是在启用unicode支持的情况下构建的:u修饰符可用,并且自PHP 4.1.0开始工作,当PHP使用捆绑的PCRE库构建时。

然而,一些Linux发行版针对他们自己的PCRE构建构建了PHP,它没有启用unicode支持,因此u修饰符不适用于这些构建。

解决方案是使用替代PHP包。

答案 1 :(得分:1)

这取决于使用--enable-utf8编译的PCRE。

相关问题