The preg_match_all in my previous message didn't work for multiline code so it was pretty useless in this case.
I rewrote it a bit and this worked better.
The key in this code is the capture of output buffering in streval that reclaims the code sent to the browser by eval.
function streval($code) {
ob_start();
eval($code);
$temp = ob_get_contents();
ob_end_clean();
return $temp;
}
function mixeval($str) {
$result = "";
while(($n = strpos($str,"<?")) !== false) {
$result .= substr($str, 0, $n);
if(substr($str, $n+2, 3) == "php") {
$str = substr($str, $n + 5, strlen($str));
} else {
$str = substr($str, $n + 2, strlen($str));
}
if(($n = strpos($str, "?>")) !== false) {
$result .= streval(substr($str, 0, $n));
$str = substr($str, $n + 2, strlen($str));
} else {
return $result;
}
}
return $result.$str;
}
Maybe it's not the most efficient stringhandling but it gets the job done 😉