Javascript正则表达式代码到PHP正则表达式?

时间:2014-12-21 09:50:33

标签: javascript php regex preg-replace

我有以下java脚本正则表达式,我需要转换为类似的PHP转换器。

text = text.replace(/R/g, "ූ");

有人可以帮助我将其转换为PHP吗?

2 个答案:

答案 0 :(得分:1)

它在php中的正则表达式对应物将是:

preg_replace( '/R/', 'your replacement string', $text );

$ text = javascript代码中“text”的值。

但是,对于简单的文本替换,正则表达式很昂贵。如果使用简单的字符串函数无法解决问题,则只使用正则表达式。

答案 1 :(得分:1)

非常相似:

$text = preg_replace('/R/', "ූ", $text);

请查看preg_replace documentation

相关问题