Useful Notes for phpinfo() & Capturing Output of phpinfo()

I recently needed to capture the output of phpinfo() for a to a log upon install. I’d been able to do this in the past but couldn’t quite remember how I managed it. This is where ob_start() and ob_flush() come into their own.

August 16, 2014

~

I recently needed to capture the output of phpinfo() for a to a log upon install. I’d been able to do this in the past but couldn’t quite remember how I managed it. This is where ob_start() and ob_flush() come into their own.

To get the contents of phpinfo(); into a variable, you can use the following:

ob_start();
phpinfo();
$strPhpInfo = ob_get_contents();
ob_clean();

The variable $strPhpInfo will now contain the output from phpinfo().

A side note, if you only want the variables section of phpinfo(), then use: