Ciao a tutti, un mio amico mi ha creato un template engine nel suo massimo delle possibilità.
Codice PHP:
<?php
class tplEngine
{
var $tpl_file;
var $tpl_code;
var $tpl_output;
var $rpl_start;
var $rpl_end;
function tplEngine()
{
$this -> tpl_file = "";
$this -> tpl_code = "";
$this -> tpl_output = "";
$this -> rpl_start = "{";
$this -> rpl_end = "}";
}
function load($tpl_file)
{
if(empty($tpl_file) || !file_exists($tpl_file) || !is_file($tpl_file))
{
return false;
}
$this -> tpl_file = $tpl_file;
if(false !== ($handle = fopen($tpl_file, "r")))
{
$size = filesize($tpl_file);
if(false !== ($code = fread($handle, $size)))
{
fclose($handle);
$this -> tpl_code = $code;
$this -> tpl_output = $code;
return true;
}
fclose($fp);
}
return false;
}
function assign($var, $value="")
{
if(empty($this -> tpl_output))
{
return false;
}
$replace = $this -> rpl_start . $var . $this -> rpl_end;
$this -> tpl_output = str_replace($replace, $value, $this -> tpl_output);
return true;
}
function ereg_assign($var, $value="")
{
if(empty($this -> tpl_output))
{
return false;
}
$replace = $var;
$this -> tpl_output = eregi_replace($replace, $value, $this -> tpl_output);
return true;
}
function insert($var, $inc_file="", $once=false)
{
if(empty($inc_file) || !file_exists($inc_file) || !is_file($inc_file))
{
return false;
}
$replace = $this -> rpl_start . $var . $this -> rpl_end;
if(substr_count($this -> tpl_output, $replace) < 1)
{
return false;
}
ob_start();
if($once == true)
{
include_once($inc_file);
}
else
{
include($inc_file);
}
$contents = ob_get_contents();
ob_end_clean();
$this -> tpl_output = str_replace($replace, $contents, $this -> tpl_output);
return true;
}
function out()
{
echo $this -> tpl_output;
}
function reset()
{
$this -> tpl_output = $this -> tpl_code;
}
}
?>
e io mentre creo la mia pagina php e la mia html funziona tutto ma quando devo fare un ciclo, nn funziona.
qualcuno sa come aiutarmi, oppure ha qualcosa di fatto? nn consigliatemi smarty o simili