I have the following php code in utf-8 php file:
var_dump(setlocale(LC_CTYPE, 'de_DE.utf8', 'German_Germany.utf-8', 'de_DE', 'german')); var_dump(mb_internal_encoding()); var_dump(mb_internal_encoding('utf-8')); var_dump(mb_internal_encoding()); var_dump(mb_regex_encoding()); var_dump(mb_regex_encoding('utf-8')); var_dump(mb_regex_encoding()); var_dump(preg_replace('/\bweiß\b/iu', 'weiss', 'weißbier'));
I want the last regular expression to replace only complete words, not parts of words.
On my Windows computer, it returns:
string 'German_Germany.1252' (length=19) string 'ISO-8859-1' (length=10) boolean true string 'UTF-8' (length=5) string 'EUC-JP' (length=6) boolean true string 'UTF-8' (length=5) string 'weißbier' (length=9)
On a web server (linux) I get:
string(10) "de_DE.utf8" string(10) "ISO-8859-1" bool(true) string(5) "UTF-8" string(10) "ISO-8859-1" bool(true) string(5) "UTF-8" string(9) "weissbier"
Thus, the regex works as I expected on windows, but not on linux.
So, the main question: how should I write my regular expression only to match word boundaries?
Secondary questions are how I can tell Windows that I want to use utf-8 in my php application.
php regex pcre utf-8 word-boundary
tomsv Mar 12 '10 at 13:08 2010-03-12 13:08
source share