i'm trying to do
$text = preg_replace('/\bمرحبا بك\b/', 'NEW', $text);
but its not working, i think this function does not support arabic
i'm trying to do
$text = preg_replace('/\bمرحبا بك\b/', 'NEW', $text);
but its not working, i think this function does not support arabic
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);
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.
Just take str_replace. No need for regex.
$text = 'hello bمرحبا بك world';
echo str_replace('bمرحبا بك', 'NEW', $text);