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.

+2


a source to share


3 answers


PCRE 4.5 supports UTF-8, but does not support Unicode properties like \pL

and does not support a flag /u

that allows them. You will need to update PCRE on your server to version 5.0 or newer. You may also need to update PHP to have support /u

for preg_replace()

.



+2


a source


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.

+2


a source


Answer your questions; Yes and no. I believe PCRE 5.0 was the threshold when UTF8 support was introduced.

0


a source







All Articles