Hi,
I've started working on this and was wondring if i was heading in the right direction. This is a function that takes an array and a template file and replaces all instances of {key} where key is a different key in the array by the data that corresponds to that key. So as an example, $array['value1'] = "Test"; would read through the template file and replace all instances of {value1} with the word Test. I just wanted to know if i was doing this the right way. It's quite a simple function which has me worried about whether or not I did this correctly.
function template($tloc, $tdata)
{
if (!file_exists($tloc))
{
echo ("Template file does not exist");
}
else
{
$tpl = file_get_contents($tloc);
foreach (array_keys($tdata) as $c)
{
$tpl = str_replace('{'.$c.'}', $tdata[$c], $tpl);
}
}
return $tpl;
}
Thanks!