PHP
  Home arrow PHP arrow Building a Template Parser Class with PHP, Part I
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building a Template Parser Class with PHP, Part I
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 72
    2005-03-22


    Table of Contents:
  • Building a Template Parser Class with PHP, Part I
  • PHP: The first templating system available
  • Defining the structure of the PHP class
  • Completing the class: the "parseFile()" and "display()" methods
  • Implementing the class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building a Template Parser Class with PHP, Part I
    ( Page 1 of 5 )

    It is easy to create a templating system in PHP; in fact, there are a number of templating system packages. But what if you're putting together a relatively small website, and don't really need one of those full-fledged systems? In this first part of a two-part article, you will learn how to create a simple but extensible PHP class for parsing templates.

    Introduction

     

    Without a doubt, PHP is one of the most popular languages currently available for fast Web development. Its extreme ease and flexibility has made it a great source for creating a wide gamut of applications, well suited for satisfying the needs of different projects. Certainly, one of the most common applications that have grown noticeably in popularity is what is widely know as a templating system.

     

    The question is: what is a templating system? Well, in short terms, it’s an easy way to create large sites with some effort to maintain a consistent appearance through the different documents. Just by having only one template file, which stores the HTML markup and the data placeholders, we are able to manipulate it with a PHP script that takes the template file and replaces those placeholders with the corresponding content, in order to generate the final version of the page. The concept behind templating is very handy, since it allows us to separate the markup and visual presentation from the logic of the application in different layers.

     

    As a PHP programmer, you probably have used some of the most popular template system packages, including the powerful Smarty, or other solutions such as Fast Template or Pat Template among others (add your own to the list). Most of these packages are full-featured and mature solutions designed to be generally implemented on medium and large size projects. They present numerous options that sometimes are pretty cumbersome, particularly when dealing with small projects, where templating needs are rather basic.

     

    Okay, right now I can hear some well-intended programmers complaining about this, arguing that those packages can be perfectly implemented for the tiny lovely pet website of Uncle Johnny, including a huge Microsoft SQL Server database system, and so on. You get the idea. But, let’s be honest. For small applications we need a simple templating system that nicely fits our needs.

     

    Because of the reasons I mentioned above, I decided to write on my own a simple but extensible PHP class for parsing templates. I designed it to satisfy the minor requirements of small websites. Fine, are you ready to put our hands on the code? Just follow me. We’re involved in this situation together!

     



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT