title: PHP HTML Template with Loop capabilities
body: <p>I would like to ask some help and ideas on how to implement a loop inside the template. I can do foearch below but how can i include it to the template and show it in the results.</p>
  
  <pre><code>foreach($results as $row) {
   $name = $row['name'];
   $address = $row['address'];
  }
  </code></pre>
  
  <p>What i want to achieve the results is something like below and how do I put the $template->publish(); in a variable so I can use it to store that data to the DB. thanks a lot.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;My Template Class&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;table&gt;&lt;tr&gt;
  &lt;td&gt;
  &lt;h3&gt;Hello William!&lt;/h3&gt;
  &lt;p&gt;The time is: 03/10/04&lt;/p&gt;
  &lt;p&gt;Embedded PHP works too!&lt;/p&gt;
  &lt;p&gt;Name goes here&lt;/p&gt;
  &lt;p&gt;Address goes here &lt;/p&gt;
  &lt;/td&gt;
  
  &lt;td&gt;
  &lt;h3&gt;Hello William!&lt;/h3&gt;
  &lt;p&gt;The time is: 03/10/04&lt;/p&gt;
  &lt;p&gt;Embedded PHP works too!&lt;/p&gt;
  &lt;p&gt;Name goes here&lt;/p&gt;
  &lt;p&gt;Address goes here &lt;/p&gt;
  &lt;/td&gt;
  
  &lt;td&gt;
  &lt;h3&gt;Hello William!&lt;/h3&gt;
  &lt;p&gt;The time is: 03/10/04&lt;/p&gt;
  &lt;p&gt;Embedded PHP works too!&lt;/p&gt;
  &lt;p&gt;Name goes here&lt;/p&gt;
  &lt;p&gt;Address goes here &lt;/p&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The template class</p>
  
  <pre><code>&lt;?
  class Template {
     public $template;
     function load($filepath) {
        $this-&gt;template = file_get_contents($filepath);
     }
     function replace($var, $content) {
        $this-&gt;template = str_replace("#$var#", $content, $this-&gt;template);
     }
     function publish() {
              eval("?&gt;".$this-&gt;template."&lt;?");
     }
  }
  ?&gt;
  </code></pre>
  
  <p>The template design.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;#title#&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h3&gt;Hello #name#!&lt;/h3&gt;
  &lt;p&gt;The time is: #datetime#&lt;/p&gt;
  &lt;? echo "&lt;p&gt;Embedded PHP works too!&lt;/p&gt;"; ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>the index.php</p>
  
  <pre><code>&lt;?
  include "template.class.php";
  $template = new Template;
  $template-&gt;load("design.html");
  $template-&gt;replace("title", "My Template Class");
  $template-&gt;replace("name", "William");
  $template-&gt;replace("datetime", date("m/d/y"));
  $template-&gt;publish();
  ?&gt;
  </code></pre>