TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   my way of templating, is this a good method? (http://www.talkphp.com/absolute-beginners/1843-my-way-templating-good-method.html)

webosb 01-02-2008 02:47 PM

my way of templating, is this a good method?
 
in terms of speed and low cpu loads, is this a good way to go?

$html = file_get_contents("home.tpl");
$html = str_replace("%fname%", $firstname, $html);
$html = str_replace("%lname%", $lastname, $html);
echo $html;

TlcAndres 01-02-2008 02:59 PM

The method is fine, it doesn't allow for much growth templating wise though.

xenon 01-02-2008 03:08 PM

It's ok if you only need search&replace.

Salathe 01-02-2008 08:35 PM

This is more of a general comment than anything particularly specific to templating but remember that str_replace can accept arrays for the first three arguments (respectively: search, replace, subject). This saves the overhead of calling the same function more than once in succesion, and prevents you from repeating code unnecessarily. More simply, you could use:

PHP Code:
$html = str_replace(array('%fname%', '%lname%'), array($firstname, $lastname), $html);


All times are GMT. The time now is 06:06 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0