I\'m messing around with templating and I\'ve run into a situation where I need to echo to the browser a template that contains html & php. How do I evaluate the PHP and
Do not read the file, but include it and use output bufferig to capture the outcome.
ob_start();
include 'main.php';
$content = ob_get_clean();
// process/modify/echo $content ...
Edit
Use a function to generate a new variable scope.
function render($script, array $vars = array())
{
extract($vars);
ob_start();
include $script;
return ob_get_clean();
}
$test = 'one';
echo render('foo.php', array('test' => 'two'));
echo $test; // is still 'one' ... render() has its own scope