note 100643 deleted from function.include by googleguy
| From: | googleguy@php.net | Date: | Wed, 01 Aug 2012 06:54:47 +0000 |
| Subject: | note 100643 deleted from function.include by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189550@lists.php.net to get a copy of this message | ||
Note Submitter: phatum at mail dot ru
----
I found a good solution how to include a text that is defined as a string and contains php-code that
must be executed.
All defined local vars are exported out to the global scope after execution.
<?php
function include_text($text) {
// executing script
eval ("?>$text");
// exporting global vars
$GLOBALS += get_defined_vars();
}
include_text ('<? $a = 2; $b = $a + 2; ?>');
echo "a = $a<br>";
echo "b = $b";
?>
Output:
a = 2
b = 4