Skip to content

Instantly share code, notes, and snippets.

@datchley
Last active September 26, 2019 16:49
Show Gist options
  • Select an option

  • Save datchley/10301405 to your computer and use it in GitHub Desktop.

Select an option

Save datchley/10301405 to your computer and use it in GitHub Desktop.
Quick and Dirty Template parsing in PHP
<?php
// the template
$template = "<h1>{TITLE}</h1>";
// add any template placeholder key/values here
$map = array(
'TITLE' => "ExtJS Sucks"
);
// Quick and dirty template parser, replace occurences of '{KEY}' with
// the value in $map[KEY] defined above (returns parsed, completed template)
$html = preg_replace_callback('/(?:{([^\}]+)\})/', function($matches) use($map) {
return $map[$matches[1]];
}, $template);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment