PHP Regex - various parsing on two servers

I have a problem that I have not seen before. The same regular expression produces two different results on two different servers.

This is the code:

preg_replace('#[^\ pL0-9_@- ]#iu', '', '!%&abc123_æøå'); 

Result on server A (php 5.2.6, Server Api: Apache 2.0 Handler):

abc123_æøå

Result on server B (php 5.2.5, Server Api: CGI / FastCGI):

123_

Anyone with ideas on why this difference is happening?

+4
source share
3 answers

It must be due

  • Locale settings
  • PHP multibyte support on / off
  • PHP mb_string.func_overload (overloading some functions to support multibytes)
+2
source

Instead, you can try mb_eregi_replace .

 mb_eregi_replace('[^\ pL0-9_@- ]', '', '!%&abc123_æøå'); 

It should work consistently on all servers that support multibyte strings, and should fix problems that may arise due to different file encodings. (Theoretically, at least.)

+1
source

Well, finally, he figured it out. The server was upgraded from php 5.2.5 to 5.2.11 (still running as cgi, though), and the problems went away with the old version.

Thanks for the feedback and suggestions!

0
source

All Articles