title: Super Basic Templating System
body: <p>I'd like to be able to replace things in a file with a regular expression using the following scheme:</p>
  
  <p>I have an array:</p>
  
  <pre><code>$data = array(
    'title' =&gt; 'My Cool Title',
    'content' =&gt; ''
  )
  </code></pre>
  
  <p>I also have a template (for clarity's sake, we'll assume the below is assigned to a variable <em>$template</em>)</p>
  
  <pre><code>&lt;html&gt;
  &lt;title&gt;&lt;% title %&gt;&lt;/title&gt;
  &lt;body&gt;&lt;% content %&gt;&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'd like to be able to use one regular expression to do the whole thing, so it can be as general as possible; The following is my stab at it (which doesn't work)</p>
  
  <pre><code>$endMarkup = preg_replace('/&lt;% ([a-z]+) %&gt;/',$data["\\1"], $template);
  </code></pre>
  
  <p>Is there a clean solution for putting associative array data into a template by array index?</p>