Skip to Content

PHP preg_replace and Arabic

Hi all,

I'm trying to use preg_replace for some Arabic text normalization. Specifically, convert all end-of-word 'ي' to 'ى'. So I used the following:

preg_replace('/ي\b/', 'ى', $subject);

Has anybody encountered this before?

TIA, Karim

Alaa's picture

php unicode support sucks

until recently pcre functions did not support UTF-8 at all, now they do but you have to add a to all your regular expressions to indicate that this is unicode text.


"i`m feeling for the 2nd time like alice in wonderland reading el wafd"

mb_ereg_replace did it

Thanks Alaa,

mb_ereg_replace did the trick - the POSIX syntax is just more annoying than PCRE...

As for /u, it didn't work, but then I did not pursue it very far.

Thanks again,

If I were you..

If I were you, I'd do my best to get it to work using preg_replace with /u modifier, because mb library is not available on many php installations.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Dr. Radut | forum