TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-02-2008, 02:47 PM   #1 (permalink)
The Contributor
 
webosb's Avatar
 
Join Date: Nov 2007
Posts: 41
Thanks: 24
webosb is on a distinguished road
Default 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;
__________________
"Things you can get access to, you should never memorize." -Albert Einstein
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
webosb is offline  
Reply With Quote
Old 01-02-2008, 02:59 PM   #2 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

The method is fine, it doesn't allow for much growth templating wise though.
TlcAndres is offline  
Reply With Quote
Old 01-02-2008, 03:08 PM   #3 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

It's ok if you only need search&replace.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-02-2008, 08:35 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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);
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
sjaq (01-03-2008)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:37 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design