note 100643 added to function.include
| From: | phatum at mail dot ru | Date: | Wed, 27 Oct 2010 22:23:08 +0000 |
| Subject: | note 100643 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173533@lists.php.net to get a copy of this message | ||
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
----
Server IP: 195.54.192.44
Probable Submitter: 127.0.0.1
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- https://master.php.net/note/edit/100643
Del: integrated -- https://master.php.net/note/delete/100643/integrated
Del: useless -- https://master.php.net/note/delete/100643/useless
Del: bad code -- https://master.php.net/note/delete/100643/bad+code
Del: spam -- https://master.php.net/note/delete/100643/spam
Del: non-english -- https://master.php.net/note/delete/100643/non-english
Del: in docs -- https://master.php.net/note/delete/100643/in+docs
Del: other reasons-- https://master.php.net/note/delete/100643
Reject -- https://master.php.net/note/reject/100643
Search -- https://master.php.net/manage/user-notes.php