Posted: Mon Aug 26, 2002 2:58 am
thanks man!
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
/*
Template Function Library
*/
class class_template {
var $root_folder; //Stores root folder of template files
var $file_content; //Stores the content of tempalte files
var $filenames; //Stores the names of template files
var $variables; //Stores the variable name for the template
var $num; //Stores number of elements
function define($folder,$template_variables) {
if(is_dir($folder)) {
$this->root_folder = $folder;
} else {
$this->error_report("The root directory specified is not a directory!");
exit();
}
$this->num = 0;
while(list($key,$value) = each($template_variables)) {
if(!file_exists($this->root_folder.$value)) {
$this->error_report("$value does not exists!");
exit();
}
$this->filenamesї$i] = $value;
$this->variablesї$i] = fopen($value,"r");
$keyї$i] = $key;
$this->num++;
}
$this->num = $this->num - 1;
}
function assign($template_vairable,$value) {
for($i = 0; $i == $this->num; $i++) {
$this->file_contentї$i] = fread($this->vairablesї$i],filesize($this->filenamesї$i]));
if(strstr($this->variablesї$i])) {
$this->file_contentї$i] = str_replace("{".$template_vairable."}",$value,$this->file_content);
}
}
unset($i);
}
function print_print($order) {
$order = explode(",",$order);
$order_num = count($order);
$i = 0; $n = 0;
while($i != $this->num) {
while($n != $this->num) {
if($orderї$i] == $file_contentї$n]) {
echo $file_contentї$n];
$n = 0;
return false;
}
}
}
unset($i); unset($n);
}
function error_report($error_msg) {
echo "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Unexpected error has occured</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center"> <span style="font-family: Verdana, Arial, Helvetica, sans-serif; color: #FF0000; font-size: 12px; font-weight: bold;">".$error_msg."</span>
</div>
</body>
</html>";
}
}
?>Code: Select all
assign(".CONTENT","Hello"); assign(".CONTENT","HIYA");