Skip to content

Instantly share code, notes, and snippets.

@elton182
Created August 14, 2017 01:01
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 elton182/3893c0991ea6974b2aa8678371fd50d1 to your computer and use it in GitHub Desktop.
Save elton182/3893c0991ea6974b2aa8678371fd50d1 to your computer and use it in GitHub Desktop.
logica que faz o parse de valores {{name}}
<?php
function resolveTemplate($template,$data){
// search pattern
$pattern = '/{{([^}]+)}}/';
$callback = function ($match) use($data){
//var_dump($matches);
$string = trim($match[1]);
if(isset($data[$string])){
return $data[$string];
}
};
return preg_replace_callback($pattern, $callback, $template);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment