Simple Template Class-Example
<?php
class template
{
/*
DESCRIPTION:
A VERY simple template class. No caching or advanced functionality.
It simply opens a file and replaces any variable in the file with a syntax of
'{VARIABLE}' It is primarily designed to keep layout HTML out of php files. Right now it is case sensitive but in future versions i will probably put in a setting for that.
I will probably update it with more functionality in the future but for now it could be extended by child classes etc.
*/
var $tpl_dir = 'templates';
var $tpl_vars = array();
// PRIVATE:
function repvar($name, $value, $string)
{// Function to replace a variable
return str_replace('{'.$name.'}', $value, $string);
}
// PUBLIC:
function addvar($name, $value)
{// Add variable to be replaced in a template
$this->tpl_vars[$name] = $value;
}
function display($page)
{
$fhandle = file_get_contents($this->tpl_dir.'/'.$page);
foreach($this->tpl_vars as $name=>$value)
{
$fhandle = $this->repvar($name, $value, $fhandle);
}
return $fhandle;
}
}
/*
//EXAMPLE
$tpl = new template;
$tpl->addvar('TITLE', 'Template Test');
$tpl->addvar('CONTENT', $content);
$tpl->addvar('MENU', 'Template Test');
echo $tpl->display('main.htm');
*/
?>
Subscribe to:
Post Comments (Atom)
Labels
AJAX
(1)
Answers
(1)
Apache
(1)
Array
(16)
bug
(1)
C
(1)
C++
(1)
Calendar
(1)
Class
(1)
Commands
(1)
Cookies
(2)
Database
(2)
Date
(7)
Days
(1)
explode
(1)
File Upload
(1)
FILES
(1)
firewall
(1)
fix
(1)
Functions
(26)
GET
(1)
GMT
(1)
JavaScript
(2)
localhost
(1)
Mail
(1)
Menu
(1)
MYSQL
(13)
PERL
(1)
PHP
(36)
php.ini
(1)
POST
(1)
preg_match
(1)
Questions
(1)
Script
(1)
SMS
(2)
Solution
(1)
String
(1)
Time
(5)
Time Zone
(1)
Vista
(1)
Wamp Server
(1)
windows 7
(2)
XML
(1)
Popular Posts
-
We can imagine our universe made of different objects like sun, earth, moon etc. Similarly we can imagine our car made of different objec...
-
PHP functions are similar to other programming languages. A function is a piece of code which takes one more input in the form of paramete...
-
PHP Code: $rawPhoneNumber = "800-555-5555"; $phoneChunks = explode("-", $rawPhoneNumber) ; echo "Raw Phone Nu...
-
if ($_POST['Date'] == "") { $Date = ''; } else { $Date = $_POST['Date']; } list($Day,$Month,$Year)=...
-
Calling javascript function from php I am trying to call a javascript function from php. According to all of the exa...
-
Example #1 Sorting multiple arrays <?php $ar1 = array( 10 , 100 , 100 , 0 ); $ar2 = array( 1 , 3 , 2 , 4 ); array_m...
-
<?php $os = array( "Mac" , "NT" , "Irix" , "Linux" ); if ( in_array ( "Irix" , ...
-
A couple days ago, I documented my recent experience with my wireless network and how I got hacked. I briefly mentioned that I'm insta...
-
Creating a registration form using PHP in PHP Form Creating a membership based site seems like a daunting task at first. If you eve...
-
Opening Database Connection: PHP provides mysql_connect function to open a database connection. This function takes five parameters and...
Popular Posts
-
Send SMS through way2sms using php 1. download one rar file - click here to download 2. extract the rar file 3. ...
-
<? /* Simple and easy for modification, PHP script for SMS sending through HTTP with you own Sender ID and delivery reports. You just ...
-
Creating a registration form using PHP in PHP Form Creating a membership based site seems like a daunting task at first. If you eve...
-
if ($_POST['Date'] == "") { $Date = ''; } else { $Date = $_POST['Date']; } list($Day,$Month,$Year)=...
-
Calculate No Of Days Excluding Weekends Count the number of days between two dates that exclude weekends as non work days Count...
-
Loading a Drop Down List Using jQuery in jQuery To load a drop down list (or a simple list) from a database, there are different wa...
-
More about forms Transmission methods HTTP, the transmission protocol used for the Web, actually defines two methods for sending form i...
-
Making a login form using PHP in PHP Form This is in continuation of the tutorial on making a membership based web site. Please see t...
-
The SELECT statement is used to select data from a database. Select Data From a Database Table The SELECT statement is used to select...
-
What is php? and please explain? PHP, or PHP: Hypertext Preprocessor, is a widely used, general-purpose scripting language that was...
No comments:
Post a Comment