File: demo.php

Recommend this page to a friend!
  Classes of wim niemans  >  SIREN PHP Templating Library  >  demo.php  >  Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: demo
Class: SIREN PHP Templating Library
Template engine featuring recursion and nesting
Author: By
Last change:
Date: 6 months ago
Size: 1,961 bytes
 

 

Contents

Class file image Download
<?php

include './Snippet.class.php';

/**
 * substitute variables in text recusively with their respective values
 * syntax: {var} where var is [text]{var}[text]
 * where text is '-._[\w\d\]'
 *
 * below examples all output 'The quick brown fox jumps over the lazy dog.'
 */

// (1) demo simple replacements
$snippet = new Snippet();
$snippet->setVar('pangram', 'The {speed} {color} fox {action} over the lazy {pet}.');
$snippet->setVar('speed', 'quick');
$snippet->setVar('color', 'brown');
$snippet->setVar('action', 'jumps');
$snippet->setVar('pet', 'dog');
$snippet->parse('output', 'pangram');
echo
$snippet->tidy('output') . " \n";

// (2a) demo nimble replacements of varValues
$snippet->setVar('pangram', 'The {1} {2} fox {3} over the lazy {4}.');
$snippet->setVar('1', '{speed}');
$snippet->setVar('2', '{color}');
$snippet->setVar('3', '{action}');
$snippet->setVar('4', '{pet}');
$snippet->parse('output', 'pangram');
echo
$snippet->tidy('output') . " \n";

// (3) demo recursive replacements of varValues
$snippet->setVar('pangram', 'The {{1}} {{2}} fox {{3}} over the lazy {{4}}.');
$snippet->setVar('1', 'speed');
$snippet->setVar('2', 'color');
$snippet->setVar('3', 'action');
$snippet->setVar('4', 'pet');
$snippet->parse('output', 'pangram');
echo
$snippet->tidy('output') . " \n";

// (4) demo nimble recursive replacements
$snippet->setVar('pangram', 'The {{br}eed} {col{umn}} fox {ac{et}on} over the lazy {{idol}}.');
$snippet->setVar('br', 'sp');
$snippet->setVar('umn', 'or');
$snippet->setVar('et', 'ti');
$snippet->setVar('idol', 'pet');
$snippet->parse('output', 'pangram');
echo
$snippet->tidy('output') . " \n";

// (5) demo gotchas still working
$snippet->setVar('pangram', 'The {{br}{own}} {col{umn}} fox {action} over the lazy {{p}e{t}}.');
$snippet->setVar('own', 'eed');
$snippet->setVar('p', 'p');
$snippet->setVar('t', 't');
$snippet->parse('output', 'pangram');
echo
$snippet->tidy('output') . " \n";

?>


For more information send a message to info at phpclasses dot org.