<? class templateEngine { public $htmlContent; public function file_import($file) { $this -> htmlContent = @file_get_contents($file) or die("Not Found Template File ({$file})"); } public function template_assign($loopName,$data = array()) { preg_match("|<!-- BEGIN: {$loopName} -->(.*?)<!-- END: {$loopName} -->|is",$this -> htmlContent,$loopContent); foreach($data as $oldData => $newData) { $this -> htmlContent = preg_replace('/{'.$oldData.'}/',$newData,$loopContent[1]); } print $this -> htmlContent; } } $template = new templateEngine; $blog_post_read = mysql_query("SELECT * FROM textpages ORDER BY id ASC"); while ($post_read = mysql_fetch_array($blog_post_read)) { $template -> file_import("data.html"); $template -> template_assign("POST",array( 'ID' => $post_read["id"], 'TITLE' => $post_read["title"], 'CONTENT' => $post_read["content"] )); } ?>
<table style="border: 1px solid red;"><!-- BEGIN: POST --> <tr> <td style="border: 1px solid red;">{ID} - {TITLE} - {CONTENT}</td> </tr> <!-- END: POST --> </table>