#native_company# #native_desc#
#native_cta#

PHP-HTML Templates: A New Working Relationship Page 4

By PHP Builder Staff
on April 3, 2002

Coders will need to prepare a script that displays the Address book entries as such:

handler.php

<?php

1:     $template_filename = "TEMPLATE.html";
2:     
3:     ..... database extraction codes (omitted) ....
4:
5:      /* =============================================================== */
6:      /* ====================== Replacement Rules ====================== */
7:      /* =============================================================== */
8:      
9:      $replacement_rules = array (
10:                                 array ("<!--NAME-DATA-->", "0"),
11:                                 array ("<!--ADDRESS-DATA-->", "1")
12:                                );
13:   
14:     /* =============================================================== */
15:  
16:     $n_fcontents = template_parser ($template_filename, $replacement_rules, $recordset_array);
17:     while (list ($line_num, $line) = each ($n_fcontents))
18:     {
19:        echo "$line";
20:     }
  
?>

What the above script does is to set rules to display our
database-retreived record fields in appropriate columns in the HTML
tables. These rules will be stored in $replacement_rules array
as defined above.
The elements of $replacement_rules array simply let our script know
how to “fill in the blanks”.
The variable :
$recordset_array is a 2-dimension array that contains
records which we retrieved from database.
+---------------------------------+
|  Alvin  | Block 112 Bedok Road  |
+---------------------------------+
|  Robert | 23 Livingstone Road   |
+---------------------------------+
               :
               :
+---------------------------------+
|   John  | 556 Everton Park Road |
+---------------------------------+
Line 10 (and line 11) of the code simply is a “rule” that instructs
PHP script to replace occurances of the string <!--NAME-DATA-->
with FIELD 1 (array is “zero-based”) of the recordset provided
in $recordset_array array.