Hi I'm trying to perform a very easy templating system in PHP.
I wold to do this:
- Reading some .md file
Change all {{ variables }} with a corrispondent variable in an array like
$data( array('variable1' => 'value', 'variable2' => 'value2'));
- Manage the case when a variable doesn't exist, in order to prevent errors like "key not found in array".
Currently I've done this (not in regular expression and also it doens't work)
class Markdown{
private static $folder = 'markdowns/';
public static function fill_template($template, $array){
$text = file_get_contents(self::$folder . $template . '.md');
foreach($array as $key => $value){
$text = str_replace('{{'.$key.'}}', $value, $text);
}
return $text;
}
}
Any ideas?
Thanks