Version: 1.0
Type: Sample Code (HOWTO)
Category: File Management
License: GNU General Public License
Description: I am very new to PHP and I was so happy to figure out how to do this, after reading much "almost there" code & function descriptions. If anyone needs the output of a class/array/var to a file, instead of a display, this works great.
$classvar = Class::someFunc($otherobj->runAQuery()) ;
#start buffering (all activity to the buffer)
ob_start() ;
# dumps to buffer
var_dump($classvar) ;
# dump buffered $classvar to $outStringVar
$outStringVar = ob_get_contents() ;
# open your file with append, read, write perms
# (be sure to check your file perms)
$fp=fopen('yourlog.txt','a+');
# write output to file & close it
fwrite($fp, $outStringVar );
fclose($fp);
# clean the buffer & stop buffering output
ob_end_clean() ;