miepsik
miepsik

Reputation: 73

php multiple string replace without recursion

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?

Upvotes: 0

Views: 112

Answers (1)

jhenderson2099
jhenderson2099

Reputation: 964

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

$text2 = "aabbccdd";
$text2 = strrev($text2); // ddccbbaa

Upvotes: 0

Related Questions