Created
May 26, 2011 12:51
-
-
Save tanakahisateru/993071 to your computer and use it in GitHub Desktop.
Simple text templating
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 | |
/** | |
* Simple text templating | |
* | |
* before: "hello,{{name}}" | |
* given: array('name'=>'world') | |
* after: "hello,world" | |
*/ | |
function fill_text_template($template, $vars) { | |
$target = array(); | |
$replacement = array(); | |
foreach($vars as $k=>$v) { | |
$target[] = '{{'.$k.'}}'; | |
$replacement[] = strval($v); | |
} | |
return str_replace($target, $replacement, $template); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment