Re: Variable Replacement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



James Williams wrote:
Hey guys, I'm coding a forum right now and I just decided that I needed

James,

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) {
     print <http://php.net/print>($codeline);
   }

instead of the loop try (not that this has anything to do with the problem):

echo join('',$code);

   ?>|
   ------------------------------------------------------------------------

This simply results in a mess, with only the pictures showing up on my

could 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 before


there 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 :-)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux