2011-09-17 59 views
6

我在PHP应用程序中有一些代码,当我尝试在生产服务器上使用它时返回null,但它在开发服务器上正常工作。这里是行代码:什么是preg_match_all“u”标志依赖于?

// 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” 的任何链接或提示?的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 
+0

您是否正在测试变量或常量值?你的例子有一个变量,我认为你应该测试一个常数,以确保你在开发和生活上都做得相同。 – hakre

+1

http://php.net/manual/en/reference.pcre.pattern.modifiers.php,请参阅评论。 –

回答

1

via

结果这取决于PCRE被编译--enable-UTF8。

+0

这听起来不错 - 你能详细说明一下吗?我没有在开发或生产机器的php_info中看到。 – cwd

4

此标志取决于PCRE是否启用了unicode支持。

PHP捆绑了这个库,它通常使用unicode支持打开:u修饰符可用,并始终在PHP 4.1.0之后运行,当PHP使用捆绑的PCRE库构建时。

但是,一些Linux发行版针对他们自己的PCRE版本构建PHP,该版本没有启用unicode支持,因此u修改器不适用于这些版本。

解决方案是使用另一个PHP包。

+0

我想知道它是否已启用,以及我用什么语言告诉系统管理员我需要它?我相信这个系统是基于CentOS的。 – cwd

+0

您可以查找正在定义的PCRE_UTF8宏或不在/usr/include/pcre.h中 – arnaud576875

+0

我在生产机器上没有root权限,但是我可以进入/ usr/include和pcre.h不在那里。也用更多的信息更新了这个问题。 – cwd