Skip to content

Instantly share code, notes, and snippets.

@acwoss
Created February 16, 2017 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acwoss/da92a88e4948935bae01b69fd4b448d3 to your computer and use it in GitHub Desktop.
Save acwoss/da92a88e4948935bae01b69fd4b448d3 to your computer and use it in GitHub Desktop.
$data = [
"carro" => "Fiat Uno",
"ano" => "2017"
];
$template = "Meu carro é {{carro}}, ano {{ano}}\n";
function parse ($template, array $vars)
{
return preg_replace_callback('#{{(.*?)}}#', function($match) use ($vars) {
extract($vars);
return ${$match[1]};
}, $template);
}
echo parse($template, $data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment