View Single Post
Old 09-06-2007, 02:16 PM   #1 (permalink)
Karl
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default Tip: error_log and arrays

Output buffering can be used to capture different types of output. For example, lets say your script needs to log an array, we could achieve this like:

PHP Code:
ob_start();
print_r($szArray);
$szLog ob_get_clean();

error_log($szLog); 
What this essentially does is output the array, but becuase we have output buffering on we can catch the output and store it in a varialbe ($szLog) which we can then log to a file (or other source) via the error_log function.

Hope this tip helps someone, it can be very useful for cron type scripts.

Last edited by Karl : 09-06-2007 at 03:09 PM.
Karl is offline  
Reply With Quote