Created
February 16, 2017 00:10
-
-
Save acwoss/da92a88e4948935bae01b69fd4b448d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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