this is my code for the parser, which will parse my template before it turns into php code:
function readtemplate($file_path){
if(file_exists($file_path)&& is_readable($file_path)){
include("includes.php");
//start replacing
$readthis = file_get_contents($file_path);
$readthis = eregi_replace('"','\"',$readthis);
$readthis = eregi_replace('{%file_start%}',"print\"",$readthis);
//import replacing rules from blog
[QUOTE]$readthis = eregi_replace('{%blog_start%}',"$table_blog = $prefix . 'blog';
$table_cat = $prefix . 'cat';
$table_user = $prefix . 'user';
$sql = \"SELECT * FROM $table_blog /*WHERE blog_author ='1' AND blog_pub ='1' ORDER BY blog_id DESC LIMIT 10*/\";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetch_array($result)){}",$readthis);
[/QUOTE]
$readthis = eregi_replace('{%blog_end%}',"print\"",$readthis);
$readthis = eregi_replace('{%file_end%}',"\";",$readthis);
$readthis = eregi_replace('{%title%}',"stupid",$readthis);
print($readthis);
//eval("$readthis");
}
}
the code that i want to parse is:
{%file_start%}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
{%blog_start%}
</body>
</html>{%file_end%}
What I am trying to achieve is that to replace the {%body_start%} tag with a function in PHP which I am collecting data from the database.After that, it will be evaluated by the PHP compiler to some browser readable data.