apres avoir declarer ,assigner les variables , writer les valeurs il suffit
de faire un echo $variable->html; pour afficher le template modifier
à propos des bloc , $variable->html; contient le modéle $variable->bloc contient les bloc empilé & modifier LOL.
class templates
{
var $nom;
var $html;
var $fields;
var $loop;
var $bloc;
function templates($nom,$dossier="templates/",$extend=".tpl")
{
$this->nom = $dossier.$nom.$extend;
if(file_exists($this->nom))
{
if(!$pfichier = fopen($this->nom, "r"))
{
$this->halt_template("Impossible d’ouvrir le fichier.");
}
$this->html = fread($pfichier, filesize($this->nom));
fclose ($pfichier);
if(get_magic_quotes_runtime() == 1)
{
stripslashes($this->html);
}
} else {
$this->halt_template("Le fichier n’existe pas.");
}
$this->fields = array();
$this->loop = array();
}
function assign($box_name,$field,$value,$loop=1)
{
if((!is_array($field)) && (!is_array($value)))
{
$this->fields[$box_name][$field] = $value;
$this->loop[$box_name][$field] = $loop;
} else {
while($new_field=array_shift($field))
{
$this->fields[$box_name][$new_field] = array_shift($value);
$this->loop[$box_name][$new_field] = $loop;
}
}
}
function write_template($box_name)
{
while ($field = array_shift($this->fields))
{
$size = count($field);
$loop = array_shift($this->loop);
while($size)
{
$key = key($field);
$value = array_shift($field);
if($vloop = array_shift($loop))
{
$this->html = preg_replace("(<".$key.">)",$value,$this->html,$vloop);
} else {
$this->html = preg_replace("(<".$key.">)",$value,$this->html);
}
$size--;
}
}
}
function write_bloc($bloc_name)
{
$bloc_tmp = $this->html;
while ($field = array_shift($this->fields))
{
$size = count($field);
$loop = array_shift($this->loop);
while($size)
{
$key = key($field);
$value = array_shift($field);
if($vloop = array_shift($loop))
{
$bloc_tmp = preg_replace("(<".$key.">)",$value,$bloc_tmp,$vloop);
} else {
$bloc_tmp = preg_replace("(<".$key.">)",$value,$bloc_tmp);
}
$size--;
}
}
$this->bloc .= $bloc_tmp;
}
function clear_template($value=' ')
{
$this->html = preg_replace("(<[0-9a-zA-Z_-]*>)",$value,$this->html);
}
function empty_bloc()
{
$this->bloc = "";
}
function halt_template($message)
{
die ("$message : Templates session halted.");
}
}
$test=new templates('test');
$test->assign('test','php','<?php');
$test->assign('test','/php','?>');
$test->assign('test','include','include "');
$test->assign('test','/include','";');
$test->write_template('test');
echo $test->html;
exit();
?>
crée un rep tpl
créer le fichier test.tpl dedans (c'est un fichier html en faite)
fichier : test.tpl
<html>
<head>
<title>%%title%%</title>
</head>
Welcome %%nom%%
</Html>
créer le fichier test.php sur la racine pas dans tpl/
fichier : test.php
<?php
# ici fait un include ou un require ou copie directement la class template
$test=new templates('test');
$test->assign('test','title','Bienvenue sur mon site');
$test->assign('test','nom','martin');
$test->write-template('test');
echo $test->html;
exit();
?>
j'ai pas regarde avec precision ton script.
a quoi ca sert au juste.
merci
apres avoir declarer ,assigner les variables , writer les valeurs il suffit
de faire un echo $variable->html; pour afficher le template modifier
à propos des bloc , $variable->html; contient le modéle $variable->bloc contient les bloc empilé & modifier LOL.