<?php

error_reporting(-1);

// Задача: подставить переменные в строку
$data = array(
	'name'		=>	'Ivan',
	'phrase'	=>	'Hello World!'
);

$format = "{name} says: {phrase}\n";

$result = preg_replace_callback("/\\{([a-zA-Z_]+)\\}/", function ($m) use ($data) {
	
	$key = $m[1];
	if (isset($data[$key])) {
		return $data[$key];
	}
	
	throw new Exception("Inavlid placeholder: '{$m[0]}'");
	
}, $format);

echo $result;