note 37487 added to function.eval
| From: | (mark@pumptheory.com) | Date: | Mon, 17 Nov 2003 14:49:37 +0000 |
| Subject: | note 37487 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60484@lists.php.net to get a copy of this message | ||
Based on the excellent example by olivier at revenu dot nom dot fr, I have extended it to allow the
<?= ... ?> tagged style of embedded php code:
<?php
function eval_buffer($string) {
ob_start();
eval("$string[2];");
$return = ob_get_contents();
ob_end_clean();
return $return;
}
function eval_print_buffer($string) {
ob_start();
eval("print $string[2];");
$return = ob_get_contents();
ob_end_clean();
return $return;
}
function eval_html($string) {
$string = preg_replace_callback("/(<\?=)(.*?)\?>/si",
"eval_print_buffer",$string);
return preg_replace_callback("/(<\?php|<\?)(.*?)\?>/si",
"eval_buffer",$string);
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37487
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37487&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37487&report=yes
Search -- http://master.php.net/manage/user-notes.php