Differences PHP PCRE on Testing and Hosting Servers
I have the following regex, which works fine on my test server, but just returns an empty string on my hosted server.
$text = preg_replace('~[^\\pL\d]+~u', $use, $text);
Now I'm pretty sure it boils down to the server version of PCRE not compiled with support for Unicode properties. The differences in the two versions are as follows:
My server:
PCRE version 7.8 2008-09-05
Compiled with
UTF-8 support
Unicode properties support
Newline sequence is LF
\R matches all Unicode newlines
Internal link size = 2
POSIX malloc threshold = 10
Default match limit = 10000000
Default recursion depth limit = 10000000
Match recursion uses stack
Hosting Server:
PCRE version 4.5 01-December-2003
Compiled with
UTF-8 support
Newline character is LF
Internal link size = 2
POSIX malloc threshold = 10
Default match limit = 10000000
Match recursion uses stack
Also note that the version on the hosting server (the same PHP version compiled) is quite old.
What confuses me is that pcretest doesn't work on both servers from the command line with
re> ~[^\\pL\d]+~u
** Unknown option 'u'
although this regex works fine when run from PHP on my server.
So I guess my questions are, is the regex failing on the hosting server due to the lack of Unicode properties? Or is there something else I am missing?
Thanks everyone, Gaz.
a source to share
Most likely the PCRE on the host server does not support UTF8 support.
pcretest uses different variations. This is "8" for UTF-8 instead of "u". This is the reason for the error.
Also note that different PCRE libraries can be used in PHP or Apache or CLI versions on the same machine.
a source to share