|
<?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;
}
?>
|