PHP Classes

File: example_all.php

Recommend this page to a friend!
  Classes of Gianluca Zanferrari   abc template   example_all.php   Download  
File: example_all.php
Role: Example script
Content type: text/plain
Description: example all
Class: abc template
Template engine that replaces tags in PHP scripts
Author: By
Last change:
Date: 14 years ago
Size: 1,353 bytes
 

Contents

Class file image Download
<?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');
?>