Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-27-2003, 08:33 AM   #1 (permalink)
randy
Registered User
 
randy's Avatar
 
Join Date: May 2003
Location: Gettysburg, PA
Posts: 7
randy is on a distinguished road
Easy Template System

Just thought I would throw this out and see what replies I get back.

I am working on a open source PHP project that I started and I really wanted it to support templates. Templates are great for separating design from processing and allow themes to be created for sites without needing to alter the PHP code.

However, the choices seemed a little complicated for what I wanted. I really didn't want to get into the whole object oriented thing. I wanted it to be simple and understandable to anyone who has a very basic understanding of PHP.

This is what I ended up using.

It's basically a string replace system, but it works, and as we all know, that's the most important thing.

First we create a very simple template file(basic.tpl). This file can be named with really any extension, I use tpl just as a note to myself that it's a template file.

<html>
<body>
This site belongs to {owner_name}.
</body>
</html>

Next, we create the PHP file to read the template and produce the final output.
output.php

PHP Code:
<?php
$my_name 
"Randy";
$html implode(''file("basic.tpl"));
$html str_replace("{owner_name}"$my_name$html);
echo 
$html;
?>
Now when someone goes to output.php in the web browser they get this.

This site belongs to Randy.

Pretty simple, but effective.
randy is offline   Reply With Quote
Reply

Bookmarks

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

BB 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
checking system configuration with JAVA callmefiero Java 3 08-26-2004 02:38 AM
Couln't find any template, giving up infinite_root PHP 5 05-25-2004 08:07 PM
Thread Message Board system Nitro PHP 2 11-18-2003 07:10 AM
Student hackers: we didn't defeat campus debit card system redhead Code Newbie News 0 07-15-2003 12:02 PM
SkipList Template Class!!! dhaas Standard C, C++ 1 04-01-2003 01:03 PM


All times are GMT -8. The time now is 10:53 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting