site logo image  |   home   |   advanced scripts   |   custom script   |   forum   |   contact us   |   links  | 
 



 function name: compile_template
 
 language:  php
 platforms:  linux/unix
 
 description:   simple template parser function
 
    

<?php
/**
*    simple teplate parse function 
*    
*    @param    templateFileName - template file name
*    @return   parsed html code
*    simple syntax: [variable name] - replace global variable 
*    can use php code in template <?php   ...      ?>
*/

function compile_template($templateFileName) {
  if (!
file_exists($templateFileName))    {
      return 
FALSE;
  }
  
ob_start();
  include(
$templateFileName);
  
$result ob_get_contents();
  if(
preg_match_all("'[\[](.*?)[\]]'si",$result,$maches)) {
      foreach(
$maches[1] as $variableName) {
        
$value $GLOBALS[$variableName];
        
$result preg_replace("(\[$variableName\])",$value,$result);
      }    
  }
  
ob_end_clean();
  return 
$result;

}

?>

 
 

2checkout

hotscripts.com


     
     
  © 2005 - 2007 www.SourceWorkshop.com    All right reserved.