Does anyone know how I can generate a new PHP file from a PHP file? I've tried something like
$foo="bar";
$file="test.php";
$file_handle=fopen($file, w);
if (!$file_handle){
die ("Cannot open $file");
}
$write=<<<EOD
<?php
include('header.php');
$a="Hello World";
$var=$foo;
include('footer.php');
?>
EOD;
fwrite($file_handle, $write);
fclose($file_handle);
?>
I eventually want the new file test.php to contain:
<?php
include('header.php');
$a="Hello World";
$var="bar";
include('footer.php');
?>
Notice how $foo needs to be evaluated to the string "bar" before being assigned to $write
Is it possible to
a) assign php code to string for fwrite()?
b) evaulate some variables in that code before assigning it to the string?
Thanks