Skip to content

Instantly share code, notes, and snippets.

@fordnox
Created September 8, 2011 09:23
Show Gist options
  • Save fordnox/1203009 to your computer and use it in GitHub Desktop.
Save fordnox/1203009 to your computer and use it in GitHub Desktop.
Replace variables {{ group.key }} in $content to values from $rep[group][key] array. Requires PHP 5.3
/* replace variables {{ group.key }} in $content to values from $rep[group][key] array */
$parsed = preg_replace_callback('/{{.([a-z]+\.[a-z]+).}}/i',
function($v) use ($rep) {
$match = $v[0];
$match = str_replace(' ', '', $match);
$match = str_replace('{', '', $match);
$match = str_replace('}', '', $match);
list($group, $key) = explode('.', $match);
return isset($rep[$group][$key]) ? $rep[$group][$key] : $v[0] ;
},
$content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment