Tôi có một số mã trong một ứng dụng PHP trả về null khi tôi thử và sử dụng nó trên máy chủ sản xuất, nhưng nó hoạt động tốt trên máy chủ phát triển. Đây là dòng mã:Cờ preg_match_all `u` phụ thuộc vào điều gì?
// use the regex unicode support to separate the UTF-8 characters into an array
preg_match_all('/./us', $str, $match);
Cờ u
phụ thuộc vào điều gì? Tôi đã thử nghiệm với mb_string
được bật và tắt và có vẻ như nó không ảnh hưởng đến nó.
Các lỗi tôi nhận được là
preg_match_all: Compilation failed: unknown option bit(s) set at offset -1
hơn thông tin
đây là một trong các tùy chọn trên máy chủ prodction:
'--with-pcre-regex=/opt/pcre'
và ở đây là các phần pcre
Picture.png http://img829.imageshack.us/img829/8524/pictureke.png
Tôi tin rằng đây là @Wesley lưu ý đã đề cập đến:
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.
Bất kỳ liên kết hoặc lời khuyên về cách để "xây dựng PCRE để bao gồm UTF-8"?
kết quả 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
Bạn có đang thử nghiệm một biến hoặc giá trị không đổi không? Ví dụ của bạn có một biến, tôi nghĩ bạn nên thử nghiệm với một hằng số để đảm bảo bạn đang làm tương tự trên dev và live. – hakre
http://php.net/manual/en/reference.pcre.pattern.modifiers.php, xem các nhận xét là tốt. –