<?php
 
/*
 
* this is an example with tabular data like data from a database; it is passed as multidimensional array where: 
 
* in the 1st level are given the tags to be replaced.
 
* in the 2nd level the values.
 
* then the data is putted in another template replacing some tags (no tabular)
 
*/
 
 
/*
 
* template processor
 
*/
 
require('class_template.php');
 
 
/*
 
* reads the template file row.html
 
*/
 
$page = new Page("row.html");
 
 
/*
 
* makes 4 id numbers
 
*/
 
for($i=0;$i<=3;$i++){
 
    $id[] = $i;
 
}
 
 
/*
 
* here we go; replace all placeholders in row.html with the tabular data (note the LOOP paramaeter)
 
*/
 
$page->replace_tags(array(
 
                    'id' => $id
 
                    ,'name' => array('john','mary','susy','bob')
 
                    , 'age' => array('22','45','67','89')
 
                    ), 'loop');
 
 
/*
 
* set the parsed template data in a variable (note the parameter FALSE)
 
*/
 
$tabular = $page->output('ISO-8859-15', FALSE);
 
 
/*
 
* reads the template file page_with_tabular.html
 
*/
 
$page = new Page("page_with_tabular.html");
 
 
/*
 
* here we go; replace all placeholders in page_with_tabular.html
 
*/
 
$page->replace_tags(array(
 
                'first' => 'This is my first sentence'
 
                ,'rand' => 'And this is my random #: ' . rand(100,999)
 
                , 'tabular' => $tabular // the tabular data
 
                ));
 
 
/*
 
* send the data to browser
 
*/
 
$page->output('ISO-8859-15');
 
?>
 
 |