note 56641 deleted from function.eval by peehaa
| From: | peehaa@php.net | Date: | Mon, 09 Dec 2013 12:00:00 +0000 |
| Subject: | note 56641 deleted from function.eval by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197869@lists.php.net to get a copy of this message | ||
Note Submitter: matt at mattsoft dot net
----
to load a php file to a variable then execute it, try this
<?php
$code=file_get_contents("file.php");
$code=str_replace('<'.'?php','<'.'?',$code);
$code='?'.'>'.trim($code).'<'.'?';
eval($code);
?>
using < ?php within eval does not work, but < ? does. in case there is html in the file
loaded, the script doesn't remove the < ?php and ? >, but insted adds ? > and < ?
around the code loaded from the file. it's simple and works very well. I also broke up the tags
in the 3rd and 4th lines of code to keep from having problems if the lines are commented out.