$str = 'aa__cc__ee';
$a = array('bb', 'dd');
echo preg_replace('/_{2}?/e', 'array_shift($a)', $str);aabbccddee
不过php5.5已经取消了修饰符“e”,所以还是前瞻点,以免以后改起来麻烦$str = 'aa__cc__ee';
$a = array('bb', 'dd');
echo preg_replace_callback('/_{2}?/', function($r) use (&$a) { return array_shift($a); }, $str);