php - How to append to file using ob_start -
i have looked quite while now, see if it's possible "append" file if using ob_start php.
i have tried following did not work. way of achieving this?
<?php $cachefile = 'file.txt'; if ( (file_exists($cachefile)) && ((fileatime($cachefile) + 600) > time()) ) { $content = file_get_contents($cachefile); echo $content; } else { ob_start(); // write content echo '<h1>hello world</h1>'; $content = ob_get_contents(); ob_end_clean(); file_put_contents($cachefile,$content,'a+'); // added a+ echo $content; } ?> i borrowed above example post on s.o.
file_put_contents doesn't work way. append, need use fopen, fwrite , fclose manually.
$file = fopen($cachefile, 'a+'); fwrite($file, $content); fclose($file);
Comments
Post a Comment