note 84461 deleted from function.eval by tularis
| From: | tularis@php.net | Date: | Tue, 15 Jul 2008 12:49:23 +0000 |
| Subject: | note 84461 deleted from function.eval by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141532@lists.php.net to get a copy of this message | ||
Note Submitter: Eirik
Reason: bad code
----
I made this function to evaluate php code inside strings
<?php
function eval_string($source) {
preg_match_all("/<\?(?:php)?(.*)\?>/is", $source, $codes, PREG_SET_ORDER);
foreach($codes as $code) {
ob_start();
eval($code[1]);
$result = ob_get_clean();
$source = preg_replace("/<\?(:php)?.*\?>/is", $result, $source, 1);
}
return $source;
}
$text = 'Hello <?php echo "World"; ?>';
echo eval_string($text);
?>