0

I have following java script regular expression which i need to convert to similar php converter.

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

Can someone help me to convert this into PHP ?

4
  • Just to replace letter R you don't even need a regex Commented Dec 21, 2014 at 9:53
  • 2
    php.net/manual/en/function.preg-replace.php if you really want to use a regular expression for replacing a character. Otherwise use php.net/manual/en/function.str-replace.php Commented Dec 21, 2014 at 9:54
  • str_replace('R', '...'); Commented Dec 21, 2014 at 10:00
  • no i need regex, becos this just a peice of code only, plus i know i how to do it but only issue is i dont how to do the \g in the php ? Commented Dec 21, 2014 at 10:42

2 Answers 2

1

It's very similar:

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

Have look at the preg_replace documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

how do i add the option option "\g" ??
@mahen3d: There is no option g, it is implicit with preg_replace.
1

its regex counterpart in php will be :

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

$text = the value of 'text' in your javascript code.

However, for simple text replace, regular expressions are expensive. If your problem can't be solved using simple string functions then only use regex.

2 Comments

i dont think there is a option "\g" , that the problem
sorry, my mistake, '/R/' will do

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.