preg_replace匹配整个单词在阿拉伯语

时间:2013-07-27 13:48:21

标签: php regex

我正在尝试

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

但它不起作用,我认为这个功能不支持阿拉伯语

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

2 个答案:

答案 0 :(得分:6)

如果您的文本采用UTF-8编码,请将'u' modifier附加到您的正则表达式模式以获得Unicode支持。

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

答案 1 :(得分:0)

只需str_replace。不需要正则表达式。

$text = 'hello bمرحبا بك world';
echo str_replace('bمرحبا بك', 'NEW', $text);