I'm new to web programing and just started using php. I wonder if there's a way to dynamic generate a file (like html) by passing an argument. like by calling some function
some_function($my_arr)
and
$my_arr={$obj1, $obj2, $obj3}
while obj is just a class with some class member in it. Is it possible to dynamically generate 3 file (such as html) that prints the info of three objects to some format seperately in each of them?
This script would be useful to you if this file generation is only for once and when you are not checking whether the file has already been generated earlier.
//let generate_files be our function with $array which is an array as the parameter
// this script generates txt files with names as array element values
function generate_files ( $array )
{
foreach ( $array as $value )
{
$handle = fopen($value.'txt', 'w') or die('Cannot open file: '.$value);
$data = 'This is the data inside each file';
fwrite($handle, $data);
}
}
If this files are generated temporarily then you can delete all these files after operation by using unlink($my_file); fumction.