简体   繁体   English

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

[英]Javascript Regular Expression Code to PHP Regular Expressions ?

I have following java script regular expression which i need to convert to similar php converter. 我有以下Java脚本正则表达式,我需要将其转换为类似的php转换器。

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

Can someone help me to convert this into PHP ? 有人可以帮我将其转换为PHP吗?

its regex counterpart in php will be : 它在php中的正则表达式对应项将是:

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

$text = the value of 'text' in your javascript code. $ text =您的JavaScript代码中“ text”的值。

However, for simple text replace, regular expressions are expensive. 但是,对于简单的文本替换,正则表达式很昂贵。 If your problem can't be solved using simple string functions then only use regex. 如果使用简单的字符串函数无法解决您的问题,则仅使用正则表达式。

It's very similar: 这非常相似:

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

Have look at the preg_replace documentation . 看一下preg_replace文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM