我在 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:编译失败:在偏移量 -1 处设置了未知选项位
更多信息
这是生产服务器上的选项之一:
'--with-pcre-regex=/opt/pcre'
这里是pcre部分
我相信这是@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”的任何链接或提示?
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
最佳答案
此标志取决于在启用 unicode 支持的情况下构建的 PCRE。
PHP 捆绑了这个库,它通常在启用 unicode 支持的情况下构建:u
修饰符可用并且自 PHP 4.1.0 起始终有效,当 PHP 使用捆绑的 PCRE 库构建时。
然而,一些 Linux 发行版根据他们自己的 PCRE 构建构建 PHP,它们没有启用 unicode 支持,因此 u
修饰符在这些构建上不起作用。
解决方案是使用替代的 PHP 包。
关于php - preg_match_all `u` 标志依赖于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7456939/