Here you go.
NOTE: vars are also made available to code post parse.
So, if you run this, it is possible to overwrite variables you did not want overwritten.
This INCLUDES all $SESSION, $GET, etc.
Using this without proper restrictions WILL result in vulnerabilities.
I tested this with this block of code:
This is a test
<br/>
<?
for($x=0;$x<10;$x++){
echo "<br/>OK!";
}
$works="yes";
?>
<hr>
Done
<?php
/*
Simple HTML/PHP Code Parser
This very simple function executes PHP code
and returns the results.
(Limited Usefulness)
@Author: Justin R Carlson, justin(AT)w3abode.com
@Date: 04/30/2004
@param code string
@return parsed/executed code string
*/
function parse($code)
{
$code=ereg_replace("\n","",$code);
preg_match_all("|<\?(.*)\?>|U",$code,$out);
for($i=0;$i<count($out[1]);$i++){
ob_start();
eval($out[1][$i]);
$executed = ob_get_contents();
ob_end_clean();
$code = str_replace($out[0][$i],$executed,$code);
}
return $code;
}
?>