ما رايكم الان خرجت بنظام قوالب يناسب سكربتي تقريبا اقتبستها من درس استاذي حازم علي ومن درس استاذي ضيف الله العتيبي
كود PHP:
<?php
class daif_template{
var $files = array();
var $vars;
var $fid;
//Function to load a template file.
function load_file($fid, $filename){
$this->fid = $fid;
$this->files[$this->fid] = file_get_contents($filename);
}
//Function to parse the Template Tags
function parse(){
//Foreach Statement
$this->files[$this->fid] = preg_replace("'<LOOP NAME=\"(.+)\">'i","<? foreach(\$this->vars[\\1] as \$key=>\$var){ ?>",$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace("'</LOOP>'i","<? } ?>",$this->files[$this->fid]);
//IF Statement
$this->files[$this->fid] = preg_replace("'<IF NAME=\"(.+)\">'i","<? if(\$this->vars[\\1]){ ?>",$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace("'</IF>'i","<? } ?>",$this->files[$this->fid]);
//Include Statement
$this->files[$this->fid] = preg_replace("'<INCLUDE FILENAME=\"(.+)\">'i","<? include(\"\\1\"); ?>",$this->files[$this->fid]);
//Foreach Variables
$this->files[$this->fid] = preg_replace("'{{(.+)}}'","<?= \$var[\\1]?>",$this->files[$this->fid]);
//Variables
$this->files[$this->fid] = preg_replace("'{(.+)}'","<?= \$this->vars[\\1]?>",$this->files[$this->fid]);
$this->files[$this->fid]= preg_replace('/\<if condtion\=\"(.*)\">/','<?if($1){?>',$this->files[$this->fid]);
$this->files[$this->fid]= preg_replace('/\<\/if\>/','<?}?>',$this->files[$this->fid]);
}
//Function to OUTPUT
function print_temp() {
$this->vars = &$GLOBALS;
$this->parse();
$fp = fopen($this->fid,"w");
fwrite($fp,$this->files[$this->fid]);
fclose($fp);
include($this->fid);
}
}
?>