[PHP5] Code Snippet: Template System Suited to small scale scripts - preCharge Forums
It shows that you are unregistered. Please register with us by clicking Here
preCharge Forums


Nav Green LeftNav Right
preCharge Forums > Website Design & Development > Programming > PHP » [PHP5] Code Snippet: Template System Suited to small scale scripts


Reply
Tcat Right
 
LinkBack Thread Tools Display Modes Tcat Right
Old 07-26-2006   #1 (permalink)
Gamelab
Junior Member
 
Join Date: Jul 2006
Age: 19
Posts: 11
Default [PHP5] Code Snippet: Template System Suited to small scale scripts

I wrote this for personal use when I needed a simple template system for a blog script.

Code:
<?php

function mk_temp($template,$str_replace)
{

    $temp = file_get_contents($template.'.tpl');

    foreach ($str_replace as $tag => $replacewith) {
    
    $temp = str_replace('<'.$tag.'>',$replacewith,$temp);
    
    }

    echo $temp;

}

?>
Use:

PHP:

Code:
<?php

include 'tplsys.php';

echo mk_temp('hello',array('what' => 'World'));

?>
The template file:

Code:
Hello <what>!
Outputs:

Code:
Hello World!
__________________
~ Christopher Clarke
E-mail : gamelab2k@gmail.com
Gamelab is offline   Reply With Quote


Old 08-06-2006   #2 (permalink)
Naox
Member
 
Join Date: Aug 2006
Age: 19
Posts: 57
Send a message via AIM to Naox Send a message via MSN to Naox Send a message via Yahoo to Naox
Default Re: [PHP5] Code Snippet: Template System Suited to small scale scripts

nice and simple.. I like it =)
Naox is offline   Reply With Quote

Old 10-12-2006   #3 (permalink)
ScottHughes
Senior Member
 
Join Date: Sep 2006
Age: 22
Posts: 460
Default Re: [PHP5] Code Snippet: Template System Suited to small scale scripts

That's very nifty and simple. It could easily be edited to do a few different changes.
__________________
ScottHughes is offline   Reply With Quote

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Share you wap scripts here abhisar Programming 6 10-12-2006 01:08 AM
[PHP5] A review system class Seph PHP 7 07-26-2006 08:39 AM
Can you give an example of what might be best suited to place the Application_Start agaba175 .NET 0 07-26-2006 05:45 AM
[PHP5] A SQL class Seph PHP 1 07-24-2006 07:21 PM
Code Snippet: A Simple Templating Class Jamie PHP 2 07-23-2006 12:01 AM


footer left
All times are GMT. The time now is 09:49 PM.

DISCLAIMER: preCharge Risk Management is not responsible for any opinions, advice or comments expressed on the preCharge Community Forums.
preCharge® is a registered trademark of preCharge Risk Management | chargeback protection | Merchant Account Blog

Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC6

Secured Loans | Credit Card | Personal Loans | Advertising | Loans

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49