$string = ":abc and :def have apples.";
$replacements = array('Mary', 'Jane');
should become:
Mary and Jane have apples.
Right now I'm doing it like this:
preg_match_all('/:(\w+)/', $string, $matches);
foreach($matches[0] as $index => $match)
$string = str_replace($match, $replacements[$index], $string);
Can I do this in a single run, using something like preg_replace?