Basic Template Engine Fix
<p>I am attempting to make a (very) basic template engine for php. Based on my research I have found that a method that I am using is strongly disliked. I was wondering if anyone knew a great alternative to get the same result so I am not using it. And if anyone sees any other improvements that can be made please share!</p>

<p>the method that is not advised is the <code>eval()</code> method!</p>

<p>Here is the php file</p>

<pre><code>&lt;?php

class Engine {
    private $vars = array();

public function assign($key, $value) {
    $this-&gt;vars[$key] = $value;
}

public function render($file_name) {
    $path = $file_name . '.html';

    if (file_exists($path)) {

        $content = file_get_contents($path);

        foreach ($this-&gt;vars as $key =&gt; $value) {
            $content = preg_replace('/\{' . $key . '\}/', $value, $content);
        }

        eval(' ?&gt;' . $content . '&lt;?php ');

    } else {
        exit('&lt;h4&gt;Engine Error&lt;/h4&gt;');
    }
  }
}

?&gt;
</code></pre>

<p>here is the index.php file</p>

<pre><code>&lt;?php

include_once 'engine.php';

$engine = new Engine;

$engine-&gt;assign('username', 'Zach');
$engine-&gt;assign('age', 21);

$engine-&gt;render('test');

?&gt;
</code></pre>

<p>and here is just a test html file to display its basic function</p>

<p><code>My name is {username} and I am {age} years old!</code></p>

<p>outputs:</p>

<p><code>My name is Zach and I am 21 years old!</code></p>

<p>Many thanks in advance!</p>
