#native_company# #native_desc#
#native_cta#

PHP Templates: Revisited

By Polerio Babao
on September 9, 2002

To finally grasp the whole idea of this parsing concept let’s go straight on the script. I’ve coded the scripts under a class. With this you only have to import this class then use its function to parse your HTML files. To get a detailed explanation of what is this all about read the article of Wee Lep “PHP-HTML Templates: A New Working Relationship”, which can be accessed here.. The concept of this parsing was taken from his article. The only reason in which this article was put into action was because Wee Lep didn’t provide a running or working example of his concept, a problem which I also encountered when I tried to apply his scripts into my application. Taken from an extensive, serious research of various code around the net, I was able to generate these scripts which have a concept similar to what Wee Lep wanted to explain. Thus if you’re into concept and discussion I suggest you read Wee Lep article as this article is only a working example of his idea. This article is code-centric, more on application. Probably, at the end of this article you’ll be able to parse your HTML files and replace it with your desired values stored in an array. This article consisted of four topics of discussion of the templates: how to load templates, how to replace statics, how to replace dynamics. This template has been applied to my phpmylibrary.sourceforge.net application.

The Templates

To start our scripting lets first take a look at the example HTML template we would like parse. This kind of template can be edited from any HTML editor like Dreamweaver, MS Frontpage, etc., thus eliminating the confusion of webpage designer and webpage programmer and their fields of expertise. Designer will be able to freely create whatever design technique he/she wanted to make without disturbing the code of the programmer, on the other hand, the programmer simply stores their result in an array which will be encoded on HTML template created by the designer. This completely divides the world of the designer and the programmer and would probably help each other in enhancing much of their talent.
This is the desired output.


+-------------------------+-----------------------+-------------------+
| Polerio and PHPBUILDER  | Article about parsing | Some Fixed Values |
+-------------------------+-----------------------+-------------------+

	+----------+-------------------------+------------------+
	|   Date   |         Title           |      Author      |
	+----------+-------------------------+------------------+
	| 09/28/02 | Parsing Made Simple . . | Juan Tamad       |
	+----------+-------------------------+------------------+
	| 09/30/02 | PHP Templates: Revi. .  | Polerio Babao    |
	+----------+-------------------------+------------------+
	|    .     |            .            |        .         |
	+----------+-------------------------+------------------+
	|    .     |            .            |        .         |
	+----------+-------------------------+------------------+
	|    .     |            .            |        .         |
	+----------+-------------------------+------------------+

This is the HTML Template, template.html

<?php

<html><head><title></title></head>

<
body>

<
table><tr>

<
td><!--%ModuleTitle%--></td>

<
td><!--%SomeComment%--></td>

<
td><!--%FixedValues%-->

</
td></tr></table>

<
br><br>

!--%
00_BEGIN_NO_MESSAGES%-->

    <!--%
97_BEGIN_NO_MESSAGES%-->

    <
table border="1">

    <
tr><td>Date</td><td>Title</td><td>Author</td></tr>

    <!--%
9a_BEGIN_MESSAGE_LIST%-->

    <!--%
9a_ML_LOOPBEGIN%-->

    <
tr><td><!--%9adate_____%--></td><td><!--%9atitle____%--></td><td><!--%9aauthor___%--></td></tr>

    <!--%
9a_ML_LOOPEND%-->

    </
table>

    <!--%
9a_END_MESSAGE_LIST%-->

    <!--%
97_END_NO_MESSAGES%-->

<!--%
00_END_NO_MESSAGES%-->

</
body></html>

?>



1
|
2
|
3
|
4
|
5
|
6
|
7