Dec 29, 2008

Unicode and preg_replace()

When you're dealing with PHP and finally start using unicode instead of whatever non-unicode encodings, you might find a some of your symbols being transformed into rubbish, especially when dealing with non-latin alphabet.

The answer is to use a “u” flag in the expression string:

$s = preg_replace('/\s/u', $s);

No comments: