title: PHP: Inserting variables into template file - include() or file_get_contents()?
body: <p>I'm working on a project where I'm keeping all HTML content separate from the rest of the PHP code. Each instance where any HTML needs to be parsed for PHP variables is sent through a function call. Most these deal with dynamic data from the database.</p>
  
  <p>A simple example of a template file:</p>
  
  <pre><code>&lt;div id='{$data['id']}'&gt;{$data['text']}&lt;/div&gt;
  </code></pre>
  
  <p>The variables in the $data array are passed through a function call where the HTML snippet needs to be added to the output buffer:</p>
  
  <pre><code>$output .= $html-&gt;load_template('template_id', array('id' =&gt; 123, 'text' =&gt; 'Testing'));
  </code></pre>
  
  <p>The html::load_template() function simply locates the correct text file, and is supposed to load the variables and return the string as HTML. This is where I'm having issues:</p>
  
  <pre><code>    public static function load($template, $data=array()) {
         ob_start();
         include ( TEMPLATE . $template .'.tpl' );
         ob_flush();
      }
  </code></pre>
  
  <p>I've tried using include() and file_get_contents(), but to no avail - I'm looking for a simple solution where I can use the {$data['var']} syntax, preferably retaining the template HTML as a simple variable, so it can then be added to the output.</p>
  
  <p>I'm trying to avoid using eval().</p>
  
  <p>Can someone give me some guidance?</p>