variable parsing in php
<p>I written a class for loading an template file and replacing the variables with actual data and also getting the replaced data.</p>

<p>Please review my code and suggest me the best code.</p>

<p>My Code:</p>

<pre><code>&lt;?php
/**
 * This class will helpful for variable replacement from a loaded file
 * 
 * @author V V R
 * @version 1.0
 */
class Parser {
    public $dir = "";
    public $text = "";

    /**
     * To get directory location
     * @param $dir
     */
    function __construct($dir = "home/template") {
        $this-&gt;dir = $dir;
    }

    /**
     * To load the specified file from directory
     * @param $file
     */
    function loadFile($file) {
        try {
            if (file_exists ( $this-&gt;dir . "/" . $file )) {
                $this-&gt;text = file_get_contents ( $this-&gt;dir . "/" . $file );
            } else {
                throw new Exception ( $this-&gt;dir . "/" . $file . " does not exist" );
            }
        } catch ( Exception $e ) {
            error_log ( $e-&gt;getMessage () );
            die ();
        }
    }
    /**
     * To get the text from a file
     * @return text
     */
    function getText() {
        return $this-&gt;text;
    }

    /**
     * To replace the variables
     * @param unknown_type $var
     * @param unknown_type $text
     */
    function replace($var, $text) {
        $this-&gt;text = str_replace ( "{\$$var}", $text, $this-&gt;text );
    }
}

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

<p>Please suggest me best way to approach it.</p>
