rendered paste body@@Template code
<?php
class Page
{
var $page;
function Page($template = "template.html") {
if (file_exists($template))
$this->page = join("", file($template));
else
die("Template file $template not found.");
}
function parse($file) {
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
function replace_tags($tags) {
foreach ($tags as $tag => $data) {
$data = (file_exists($data)) ? $this->parse($data) : $data;
$this->page = eregi_replace("{" . $tag . "}", $data,
$this->page);
}
}
function output() {
echo $this->page;
}
}
?>
@@ page that calls template.php
<?php
include 'template.php';
$page = new Page("index.tpl");
for($i = 0; $i < 5; $i++){
$page->replace_tags(array("NAME" => 'Name', "CAT" => 'cat'));
}
$page->output();
?>