Create a PHP file using PHP? -
i'm planning creating simple script allow unexperienced in php users create code files 1 video game. have 2 files, "code.txt" , "exec.php". first file looks this:
getglobal_move_call("turntarget") getglobal_move_loadk_call("generatecsm", "15")
and "exec.php" creates "temp.php", imports user made file. it's filled "str_replace" functions, , results supposed this:
<? $temp_line = "turntarget(param1)"; file_put_contents($generated_output, $temp_line, file_append); $temp_line = "generatecsm(param1, 15)"; file_put_contents($generated_output, $temp_line, file_append); ?>
but, when echo code after these replacements, i'm getting this:
<? = "turntarget(param1)"; file_put_contents(user/apple/sites/generate/generated.txt, , file_append); = "generatecsm(param1, 15)"; file_put_contents(user/apple/sites/generate/generated.txt, , file_append); ?>
as can see, str_replace deleted variables. there solution this?
it's because use ""
in code, , php replaces $temp_line
it's actual value (null, because there no such var).
to echo php code escape $
\
$code = <<< php \$temp_line = "turntarget(param1)"; file_put_contents(\$generated_output, \$temp_line, file_append); \$temp_line = "generatecsm(param1, 15)"; file_put_contents(\$generated_output, \$temp_line, file_append); php; echo $code;
Comments
Post a Comment