Re: Variable Replacement
| From: | Jochem Maas | Date: | Thu, 03 Mar 2005 13:38:18 +0000 |
| Subject: | Re: Variable Replacement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-209913@lists.php.net to get a copy of this message | ||
James Williams wrote:
Hey guys, I'm coding a forum right now and I just decided that I neededJames, I'll assume that you're coding a forum because you feel like it. :-) (i.e. there are lots of forum 'packages' out there)
to code some variable replacement to create a simple template system. This is the code I have but it doesn't work ------------------------------------------------------------------------ |<?php $tpl = file <http://php.net/file>("tpl/head.tpl");it makes it a little less readable if you add the links to the manual next to each function call.... anyhow... what is the content of 'tpl/head.tpl'? does $tpl contain what you think it does? does $config contain what you think it does? (have you got error_reporting on 'full'?)
$code = str_replace <http://php.net/str_replace>("{sitename}",$config['sitename'],$tpl);I very much doubt that this is causing a problem BUT you might want to change that last line: from: $code = str_replace("{sitename}",$config['sitename'],$tpl); to: $code = str_replace('{sitename}',$config['sitename'],$tpl);
foreach ($code as $codeline) {instead of the loop try (not that this has anything to do with the problem): echo join('',$code);print <http://php.net/print>($codeline);}
?>| ------------------------------------------------------------------------ This simply results in a mess, with only the pictures showing up on mycould you post an example? because AFAICS the bit of code you posted should work ok.
page... I know this code is horrible but I have no idea how to go about doing this. I've never worked with reading files and whatnot beforethere are _lots_ of php template 'engines' out there; one of the most wellknown is Smarty. why not give it a whirl, it might do what you want, and even if it doesn't you can pickup a few ideas along the way (just dive into their source :-)