Skip to content

Instantly share code, notes, and snippets.

@iamuteti
Forked from JeffreyWay/template.php
Created February 15, 2016 10:56
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 iamuteti/2d70f5aab73a0fbf5cf7 to your computer and use it in GitHub Desktop.
Save iamuteti/2d70f5aab73a0fbf5cf7 to your computer and use it in GitHub Desktop.
Template Example
<?php
$template = "I am {{name}}, and I work for {{company}}. I am {{age}}.";
# Your template tags + replacements
$replacements = array(
'name' => 'Jeffrey',
'company' => 'Envato',
'age' => 27
);
function bind_to_template($replacements, $template) {
return preg_replace_callback('/{{(.+?)}}/', function($matches) use ($replacements) {
return $replacements[$matches[1]];
}, $template);
}
// I am Jeffrey, and I work for Envato. I am 27.
echo bind_to_template($replacements, $template);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment