writing to the same file recursively
Posted: Sat Apr 10, 2004 11:13 pm
i have the following function.
I use it (in command line mode) to read a php script (in the file given as $tpl), parse it and write the result to a file named $outfile. i can call it like given below.
contents of my template1.php file includes another call to the same adapt function, like given below.
since two calls involve different $tpl files, it does not end up in an infinite loop. I want both function calls to append to the same file. But they do not. Only the first call add to the file it seems. If the output files are different, they work as expected (i.e. two files will be created with expected output).
Can anybody suggest what i'm doing wrong
? If i'm not made my problem clear pls indicate 
Code: Select all
<?php
function adapt($tpl,$outfile, $mode='w'){
ob_start();
require $tpl;
$tplContents = ob_get_contents();
ob_end_clean();
$fp = fopen($outfile, $mode);
fputs($fp, $tplContents);
fclose($fp);
}
?>Code: Select all
<?php
adapt('template1.php','testout.txt');
?>Code: Select all
<?php
adapt('template2.php','testout.txt');
?>Can anybody suggest what i'm doing wrong