Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Created May 26, 2011 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanakahisateru/993071 to your computer and use it in GitHub Desktop.
Save tanakahisateru/993071 to your computer and use it in GitHub Desktop.
Simple text templating
<?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