Preg_replace с заменами массивов
$string = ":abc and :def have apples.";
$replacements = array('Mary', 'Jane');
должен стать:
Mary and Jane have apples.
Прямо сейчас я делаю это так:
preg_match_all('/:(\w+)/', $string, $matches);
foreach($matches[0] as $index => $match)
$string = str_replace($match, $replacements[$index], $string);
Могу ли я сделать это за один прогон, используя что-то вроде preg_replace?