- preg_replace_callback: documentation ( source)
- implode: documentation ( source)
- array_keys: documentation ( source)
- strtolower: documentation ( source)
<?php
$str = "and with strange aeons even {{noun}} may {{verb}}";
$data = ['noun' => 'bird', 'verb' => 'fly'];
$pattern = '/{{(' . implode('|', array_keys($data)) . ')}}/i';
echo preg_replace_callback($pattern, function($m) use($data){
return $data[strtolower($m[1])];
}, $str);