I'm currently using PHP's str_replace to replace a particular value with another, in a loop.
The problem is, str_replace will replace ALL of the instances of the first value, with the second value, rather than replacing them sequentially. For example:
$replacements = array('A', 'one', 'some');
$str = "The quick brown fox jumps over the lazy dog and runs to the forest.";
foreach($replacements as $replace){
$str = str_replace('the', $replace, $str);
}
this will ultimately return:
"A quick brown fox jumps over A lazy dog and runs to A forest."
rather than what I want which would be:
"A quick brown fox jumps over one lazy dog and runs to some forest."
What would be the most efficient way of doing this? I thought I could use preg_replace but I'm mediocre with regex.