2

i'm trying to do

$text = preg_replace('/\bمرحبا بك\b/', 'NEW', $text);

but its not working, i think this function does not support arabic

http://php.net/manual/en/function.preg-replace.php

3 Answers3

5

If your text is in UTF-8 encoding, append the 'u' modifier to your regex pattern for Unicode support.

$text = preg_replace('/\bمرحبا بك\b/u', 'NEW', $text);
Inglis Baderson
  • 779
  • 4
  • 12
1

Don't add a \b at the end of your regex. The matching should work fine when you change your code into this:

 $text = preg_replace('/\bمرحبا بك/', 'NEW', $text);

You cannot use \b at the end as well since there is a space in the word(s) you're trying to match. \b fails to match anything when there is a non word-character in the part you're trying to match.

Patrick Kostjens
  • 5,065
  • 6
  • 29
  • 46
0

Just take str_replace. No need for regex.

$text = 'hello bمرحبا بك world';
echo str_replace('bمرحبا بك', 'NEW', $text);
bitWorking
  • 12,485
  • 1
  • 32
  • 38