<?php <br /> <br />echo "testing capture of var_dump output<br />\n"; <br /> <br />// test data <br />$a = array( <br /> 'x' => 'x_value', <br /> 'y' => 'y_value', <br /> array( <br /> 'z' => 'z_value', <br /> 'w' => 'z_value' <br /> ), <br />); <br /> <br />// output-file <br />define ('OB_LOG', 'ob_test.log'); <br /> <br />// clear output-file if it exists (optional) <br />if (file_exists(OB_LOG)) { <br /> unlink(OB_LOG); <br />} <br /> <br />// method 1 - output buffer explicitly <br />ob_start(); <br />echo "test 2\n"; <br />echo "a=\n"; <br />var_dump($a); <br />error_log(ob_get_contents(), 3, OB_LOG); <br />ob_end_clean(); <br /> <br />// method 2 - use callback function to output buffer <br />ob_start('callback'); <br />echo "test 1\n"; <br />echo "a=\n"; <br />var_dump($a); <br />ob_end_flush(); <br /> <br />echo "done<br />\n"; <br /> <br />// callback function for ob_start() - only needed if using method 2 <br />function callback($buf) { <br /> error_log($buf, 3, OB_LOG); <br /> return ''; <br />} <br /> <br />?>