note 57718 added to function.eval
| From: | kalce at web7 dot pl | Date: | Wed, 12 Oct 2005 08:19:00 +0000 |
| Subject: | note 57718 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96888@lists.php.net to get a copy of this message | ||
Probably the simplest way to implement templates with using eval().
<?php
$code = "return " .
"<<<TEMPLATE\n" .
str_replace("\r", "", file_get_contents($file_name)) . "\n" .
"TEMPLATE;\n";
echo eval($code);
?>
In template you have to use heredoc syntax, so you can't use any simple function, but you can
use variables, objects and methods. Secure and simple.
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57718
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57718&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57718&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57718&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57718&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57718&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57718&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57718&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57718&report=yes
Search -- http://master.php.net/manage/user-notes.php