Skip to content

Instantly share code, notes, and snippets.

@muhamed-didovic
Forked from JeffreyWay/template.php
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save muhamed-didovic/b667f01ec74eaac81033 to your computer and use it in GitHub Desktop.

Select an option

Save muhamed-didovic/b667f01ec74eaac81033 to your computer and use it in GitHub Desktop.
<?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