I have a problem that I haven't seen before. The same regex is producing 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开发者_如何转开发 any ideas on why this difference is happening?
This must be because of
- Locale settings
- PHP multibyte strings support on/off
- PHP mb_string.func_overload (overloading of some functions for multibyte support)
You could try the mb_eregi_replace function instead.
mb_eregi_replace('[^\pL0-9_@-]', '', '!%&abc123_æøå');
Should work consistently across all servers that support multibyte strings, and should eliminate problems that you might get due to different file encodings. (Theoretically, at least.)
Well, it's finally sorted 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 everyones feedback and suggestions!
精彩评论