$string = \":abc and :def have apples.\"; $replacements = array(\'Mary\', \'Jane\');
should become:
Mary and Jane have apples.
$string = ":abc and :def have apples."; $replacements = array('Mary', 'Jane'); echo preg_replace("/:\\w+/e", 'array_shift($replacements)', $string);
Output: