Hello all,
I'm sure there must be someone here that can help me with this. When I run template.php I get this error:
Warning: The length of the needle must not be 0 in template.class on line 46
template.php:
template.class:PHP Code:<?
include("template.class");
$page_title = "title";
$bg_color = "white";
$user_name = "Justin";
$template = new template;
$template->register_file("home", "test.template");
$template->register_variables("home", "page_title,bg_color,user_name");
$template->file_parser("home");
$template->print_file("home")
?>
I know it's kind of complicated but I really need to get this working!PHP Code:<?
class template {
VAR $files = array();
VAR $variables = array();
VAR $oppinging = '{!';
VAR $closing = '!}';
//register file
function register_file($file_id, $file_name) {
$fh = fopen($file_name, "r") or die ("Couldn't open $file_name!");
$file_contents = fread($fh, filesize($file_name));
$this->files[$file_id] = $file_contents;
fclose($fh);
}
//end register file
//register variables
function register_variables($file_id, $variable_name) {
$input_variables = explode(",", $variable_name);
while (list(,$value) = each($input_variables)) {
$this->variables[$file_id][] = $value;
}
}
//end register variables
//file parser
function file_parser($file_id) {
$varcount = count($this->variables[$file_id]);
$keys = array_keys($this->files);
if ((in_array($file_id, $keys)) && ($varcount > 0)) {
$x = 0;
while ($x < sizeof($this->variables[$file_id])) {
$string = $this->varibales[$file_id][$x];
GLOBAL $$string;
$needle = $this->opening_escape.$string.$this->closing_escape;
$this->files[$file_id] = str_replace(
$needle,
$$string,
$this->files[$file_id]);
$x++;
}
}
}
//end file parser
function print_file($file_id) {
print $this->files[$file_id];
}
}
?>![]()
Thanks for the help,
Justin Sampson





Bookmarks