php_phreak_91 Posted June 21, 2007 Share Posted June 21, 2007 OK, so I was busy thinking about something new that I could do with PHP as I am always wanting to learn something new that I didn't know before. I figured, wouldn't it be cool to make a template engine, not an advanced one like Smarty, just a simple one, but it won't work I can't see anything wrong with the code and PHP is not churning out any errors. Here is the code: template.functions.php: <?php class Template { var $output; function input($page){ $this->output = include("templates/default/page_Header.html"); $this->output = include("templates/default/page_" . $page . ".html"); $this->output = include("templates/default/page_Footer.html"); $tags = array( "SITENAME" => "Template Engine Test Page", "PAGETITLE" => "$page" ); foreach ($tags as $tag => $value){ ereg_replace("{" . $tag . "}", $value, $this->output); } } function displayPage(){ print $this->output; } } ?> index.php <?php include("template.functions.php"); $template = new Template; $template->input("Index"); $template->displayPage(); ?> This should work and replace {SITENAME} and {PAGETITLE} in the html pages, but it isn't, which suggests that I have made an error somewhere in the vicinity of the foreach() section (since that is what deals with the tags). ??? Thanks in advance for any help that you may be able to provide. Quote Link to comment https://forums.phpfreaks.com/topic/56613-solved-trying-something-new-with-php-but-it-wont-work/ Share on other sites More sharing options...
php_phreak_91 Posted June 21, 2007 Author Share Posted June 21, 2007 Nevermind I figured it out, eventually: template.functions.php: <?php class Template { var $tplpage; function input($page){ $this->tplpage = join("", file("templates/default/page_" . $page . ".html")); $tags = array( "SITENAME" => "Template Engine Test Page", "PAGETITLE" => "$page" ); foreach ($tags as $tag => $value){ $this->tplpage = eregi_replace("{" . $tag . "}", $value, $this->tplpage); } } function output(){ print $this->tplpage; } } ?> Thanks for your help everyone. Quote Link to comment https://forums.phpfreaks.com/topic/56613-solved-trying-something-new-with-php-but-it-wont-work/#findComment-279584 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.