Created
August 15, 2016 17:35
-
-
Save alexsasharegan/3d1ba075675ed9c507229ab82036b862 to your computer and use it in GitHub Desktop.
Use handlebars-like syntax and do template rendering with associative arrays, where the key is var name, and the value is the rendered content.
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
<?php | |
function assoc_replace ($templateStr, $replacementList) { | |
$searchStrings = []; | |
$replacements = []; | |
foreach ($replacementList as $key => $val) { | |
array_push($searchStrings, '{{'.$key.'}}'); | |
array_push($replacements, $val); | |
} | |
return str_replace($searchStrings, $replacements, $templateStr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment