2011-09-17 60 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