Hello, I am trying to implement a system where there is a content file, template file, and then a script that places the content of the content file into a certain variable of the template file. I have this working but have one problem.
[u]The way it is set up is like this (extremely condensed):[/u]
1.) open the template file and store the contents to a variable
2.) open the content file and store the contents to a variable
3.) use preg_replace to place the content into the template at a template variable {var}
4.) echo the data
But when I try inluding another php file in content file *"[color=Navy]<?php include("anotherfile.php"); ?>[/color]"* the included file is just ignored and doesn't appear in the output. I tried using preg_replace in the main script that changes a template var *"inc"* to *"[color=Navy]<?php include(\"afile.php\"); ?>[/color]"* (Code Below). This didn't work: when I viewed the source of the output page it appeared as *"[color=Navy]<?php include("content/afile.php"); ?>[/color]"* but did not get processed.
$var = preg_replace("/inc/","<?php include(\"content/afile.php\"); ?>",$inputcontent);
Are there any ways of doing this? Any help will be greatly appreciated. [img]http://www.kirupa.com/forum/images/smilies/happy.gif[/img]
Here's the full source : (I know some of its a mess...)
<?php
include("pageids.php");
$aid = $_GET[id];
$pgid = $pid[$aid];
if (!isset($aid)){
$pgid="home.php";
}
function templatewrite($pagecontent,$templatevar,$templatefile){
if (!isset($templatefile)){
$templatefile="default.php";
}
$tivar="template/".$templatefile;
$templatecontent = file_get_contents($tivar);
$iivar="content/".$pagecontent;
$inputcontent = file_get_contents($iivar);
$inputcontent2 = preg_replace("/inc/","<?php include(\"content/error404.php\"); ?>",$inputcontent);
$preoutputdata = preg_replace("/{".$templatevar."}/",$inputcontent2,$templatecontent);
$statictags = array(
"websiteurl",
"comment"
);
$statictagsrpl = array (
"http://localhost/NewFolder/",
"comment"
);
$i=0;
while ($i < count($statictags)){
if ($i==0){
$outputdata[0] = preg_replace("/{".$statictags[$i]."}/",$statictagsrpl[$i],$preoutputdata);
}else{
$outputdata[$i]= preg_replace("/{".$statictags[$i]."}/",$statictagsrpl[$i],$outputdata[$i-1]);
}
$i++;
}
echo $outputdata[$i-1];
}
templatewrite($pgid,"main");
?>