Skip to content

Instantly share code, notes, and snippets.

@rugbyprof
Created February 23, 2012 02:02
Show Gist options
  • Save rugbyprof/1889184 to your computer and use it in GitHub Desktop.
Save rugbyprof/1889184 to your computer and use it in GitHub Desktop.
print_r to a file
<?php
//sebasg37 at gmail dot com
//If you have to catch the output without showing it at all at first (for example, if you want to append the //print_r output to a file), you can do this:
ob_start();
print_r( $some_array );
$output = ob_get_clean();
// if you want to append the print_r output of $some_array to, let's say, log.txt:
file_put_contents( 'log.txt', file_get_contents( 'log.txt' ) . $output )
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment