note 83782 deleted from function.eval by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 11:01:12 +0000 |
| Subject: | note 83782 deleted from function.eval by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197021@lists.php.net to get a copy of this message | ||
Note Submitter: trukin at gmail dot com
----
The EVAL function can be used as a fast Template system.
<?php
function parseTemplate($template, $params=array()) {
foreach ($params as $k=>$v) {
$$k = $v;
}
ob_start();
eval("?>" . implode("", file($template)) . "<?");
$c = ob_get_contents();
ob_end_flush();
return $c;
}
?>
Example:
<?php
echo parseTemplate("myTemplate.php", array('account'=>$row));
?>
and myTemplate.php can be like
<?php foreach($account as $k=>$v) : ?>
<?php echo $k; ?>: <?php echo $v; ?>
<?php endforeach; ?>