Created
March 5, 2013 22:58
-
-
Save dave1010/5095134 to your computer and use it in GitHub Desktop.
Really basic PHP templating
This file contains hidden or 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
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