$string = 'hello world {{code}},{{hello}}';
$data = ["code"=>"code2","hello"=>"hello2"];
preg_match_all ('/{{.*?}}/', $string, $matches, PREG_OFFSET_CAPTURE);
var_dump ($matches);
foreach ($matches [0] as $item)
{$lists [] = [$item [0] => $data [trim ($item [0],"{}")]];
$string = str_replace ($item [0],$data [trim ($item [0],"{}")],$string);
}
var_dump ($lists);
var_dump ($string);