Hello,
I have a template file (e.g. browse.html) where i have html. Included in the file are tags which i have
defined e.g. <php> and </php>. Inside the tags, i put php codes.
Now I have a php file which I call e.g. http://someserver/display.php
Display.php evaluates some values and stores them in variables. At the end of the file i just call a
function with the following parameters:
1. a template file
2. a list of variables (containing the values evaluated)
Here's the function:
function DisplayTemplate($templatefile, $vars)
{
$line=implode(file($templatefile), "");
eval( "global $vars;");
$vars = str_replace(",","",$vars);
$var_list = explode("\$",$vars);
$i=0;
while($i<=sizeof($var_list))
{
$line = str_replace("<%$var_list[$i]%>",$$var_list[$i],$line);
$i++;
}
$line = str_replace("\n","",$line);
preg_match_all("/<php> (.*) <\/php>/x",$line,$out,PREG_SET_ORDER);
$lines = preg_split("/<php> (.*) <\/php>/x",$line);
$loop_line=0;
while($loop_line<sizeof($lines))
{
print $lines[$loop_line];
str_replace("\n","",($out[$loop_line][1]));
eval($out[$loop_line][1]);
$loop_line++;
}
}
I call the function (DisplayTemplate) as follows:
DisplayTemplate ("browse.html", "\$category_path, \$category, \$num_rows, \$pagination, \$cat, \$link,
\$start_number, \$ma");
where $category, $num_rows, etc are the vaiables.
The template (browse.html) file looks like this:
<head>
<title>Some Title></title>
</head>
<body>
<font color="black" size="2" face="arial">
<p><b><%category_path%></b></p>
<%category%>
<%link%>
<php> include("displayNews.php"); </php>
<font color="black" size="2" face="arial">
<p align="center"><%pagination%></p>
</body>
As you have seen, the function will replace all the variables (enclosed in <% and %>) in the template
and then display (print) it on the browser.
The problem is that the line:
eval($out[$loop_line][1]);
in the function is not executed.
Any ways to circumvent this problem???
Please help.
-nad-