Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/12/2009, 10:43
Hidek1
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Tokyo - Japan !
Mensajes: 3.867
Antigüedad: 14 años, 6 meses
Puntos: 334
Respuesta: Clase Templates

Código php:
Ver original
  1. class plantilla{
  2.   function plantilla($template_file){
  3.     $this->tpl_file = $template_file;
  4.   }
  5.   function asigna_variable($vars){
  6.     $this->vars = (empty($this->vars)) ? $vars : $this->vars.$vars;
  7.   }
  8.   function muestra(){
  9.     if($this->fd = @fopen($this->tpl_file,"r")){
  10.       $this->template_file = fread($this->fd,filesize($this->tpl_file));
  11.       fclose($this->fd);
  12.       $this->mihtml = $this->template_file;
  13.       $this->mihtml = str_replace("'","\'",$this->mihtml);
  14.       $this->mihtml = preg_replace('#\{([a-z0-9\-_]*?)\}#is',"'.$\\1.'",$this->mihtml);
  15.       reset($this->vars);
  16.       while(list($key,$val) = each($this->vars)){
  17.         $$key = $val;
  18.       }
  19.       eval("\$this->mihtml = '$this->mihtml';");
  20.       reset($this->vars);
  21.       while(list($key,$val) = each($this->vars)){
  22.         unset($$key);
  23.       }
  24.       $this->mihtml = str_replace("\'","'",$this->mihtml);
  25.       return $this->mihtml;
  26.     }
  27.   }
  28. }

Código html:
Ver original
  1. <div style="border:1px solid #000;margin:15px;padding:15px;">{texto}</div>

Código php:
Ver original
  1. $Contenido = new Plantilla ( "direccionTemplate.html" );
  2. $variable_texto = "probando :P";
  3. $Contenido->asigna_variable ( array ("texto" => $variable_texto ) );
  4. $ContenidoString = $Contenido->muestra();
  5. echo $ContenidoString;


asi lo uso yo.. saludos
espero te sirva :P
__________________
More about me...
~ @rhyudek1
~ Github