- preg_match_all: documentation ( source)
- str_replace: documentation ( source)
<?php
class Simplify {
public static function Template($file, $variables) {
$template = $file;
preg_match_all("{{(\w*)}}", $template, $matches);
foreach($matches[1] as $var) {
if (array_key_exists($var, $variables)) {
$output = str_replace('{{' . $var . '}}', $variables[$var], $template);
}
}
echo $template;
}
}
$template = "hfwlei ifaugweifg uwfgyakreu fvgw fwaeuif gonwiegf {{naam}} uywanfi awyuegfawuyegf {{email}}";
$vars = array("naam" => "Joran", "email" => "info@jorandesign.nl");
Simplify::Template($template, $vars);