PHP - Extremely light templating system - Stack Overflow
→
https://stackoverflow.com/questions/4065418/php-extremely-light-templating-system
/**
* Renders a single line. Looks for {{ var }}
*
* @param string $string
* @param array $parameters
*
* @return string
*/
function renderString($string, array $parameters)
{
$replacer = function ($match) use ($parameters)
{
return isset($parameters[$match[1]]) ? $parameters[$match[1]] : $match[0];
};
return preg_replace_callback('/{{\s*(.+?)\s*}}/', $replacer, $string);
}
Wed Feb 4 17:04:00 2015
–
#permalink