PHPBuilder - var_dump() to output file

RSS Twitter

var_dump() to output file

by: john thomas
July 18, 2009

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)

# write output to file & close it
fwrite($fp, $outStringVar );

# clean the buffer & stop buffering output
ob_end_clean() ;

Comment and Contribute

Your comment has been submitted and is pending approval.

john thomas



(Maximum characters: 1200). You have characters left.