Skip to content

Instantly share code, notes, and snippets.

@dave1010
Created March 5, 2013 22:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dave1010/5095134 to your computer and use it in GitHub Desktop.
Save dave1010/5095134 to your computer and use it in GitHub Desktop.
Really basic PHP templating
function template($string, $replace){
$keys = array_map(function($k) {
return '{'.$k.'}';
}, array_keys($replace));
$vals = array_values($replace);
return str_replace($keys, $vals, $string);
}
echo tempate("Hello {name}, today is {weather}!", array(
'name' => 'Dave',
'weather' => 'sunny',
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment