0

So I have this piece of code

$text2 = "abcd";
$text2 = str_replace(
    array('a', 'b', 'c', 'd'),
    array('dbac ', 'cabd ', 'bacd ', 'adbc '),
    $text2
);

and text2 is "adbc bacadbc abadbc abacadbc bacadbc abadbc bacadbc adbc" but I wanted to have dbac cabd bacd adbc. How to avoid that recursion replacing?

2
  • 2
    if you use only one-symbol parterns, function strtr will help - eval.in/884555 Commented Oct 22, 2017 at 13:29
  • OK I changed code to show that it's not simple one symbol or reverse Commented Oct 22, 2017 at 13:34

1 Answer 1

0

It looks like you could simply use the PHP strrev function:

$text2 = "aabbccdd";
$text2 = strrev($text2); // ddccbbaa
Sign up to request clarification or add additional context in comments.

1 Comment

That ddccbbaa is just an example. I have to do different replacement

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.