Yo trabajo con templates.. te paso la classe.. funciona perfect :B saludos!
Código php:
Ver original<?php
class plantilla {
function plantilla($template_file) {
$this->html_file = $template_file;
}
function asigna_variables($vars) {
$this->vars = (empty ( $this->vars )) ?
$vars : $this->vars . $vars; }
function muestra() {
if (! ($this->fd = @fopen ( $this->html_file, 'r' ))) { sostenedor_error ( 'error al abrir la plantilla ' . $this->html_file );
} else {
$this->template_file = fread ( $this->fd, filesize ( $this->html_file ) ); $this->mihtml = $this->template_file;
$this->mihtml = str_replace ( "'", "\'", $this->mihtml ); $this->mihtml = preg_replace ( '#\{([a-z0-9\-_]*?)\}#is', "' . $\\1 . '", $this->mihtml ); while ( list ( $key, $val ) = each ( $this->vars ) ) { $$key = $val;
}
eval ( "\$this->mihtml = '$this->mihtml';" ); while ( list ( $key, $val ) = each ( $this->vars ) ) { }
$this->mihtml = str_replace ( "\'", "'", $this->mihtml ); echo $this->mihtml;
}
}
function devuelve() {
if (! ($this->fd = @fopen ( $this->html_file, 'r' ))) { self::sostenedor_error ( 'error al abrir la plantilla ' . $this->html_file );
} else {
$this->template_file = fread ( $this->fd, filesize ( $this->html_file ) ); $this->mihtml = $this->template_file;
$this->mihtml = str_replace ( "'", "\'", $this->mihtml ); $this->mihtml = preg_replace ( '#\{([a-z0-9\-_]*?)\}#is', "' . $\\1 . '", $this->mihtml ); while ( list ( $key, $val ) = each ( $this->vars ) ) { $$key = $val;
}
eval ( "\$this->mihtml = '$this->mihtml';" ); while ( list ( $key, $val ) = each ( $this->vars ) ) { }
$this->mihtml = str_replace ( "\'", "'", $this->mihtml ); return $this->mihtml;
}
}
function sostenedor_error($error) {
$miplantilla = new plantilla ( "error.html" );
$miplantilla->asigna_variables ( array ('ERROR' => $error ) ); return $miplantilla->muestra ();
}
function variable_plantilla($variable) {
$this->template_file = $variable;
$this->mihtml = $this->template_file;
$this->mihtml = str_replace ( "'", "\'", $this->mihtml ); $this->mihtml = preg_replace ( '#\{([a-z0-9\-_]*?)\}#is', "' . $\\1 . '", $this->mihtml ); while ( list ( $key, $val ) = each ( $this->vars ) ) { $$key = $val;
}
eval ( "\$this->mihtml = '$this->mihtml';" ); while ( list ( $key, $val ) = each ( $this->vars ) ) { }
$this->mihtml = str_replace ( "\'", "'", $this->mihtml ); return $this->mihtml;
}
}
?>