Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force phpinfo() to output its stuff without formatting. Just like in CLI mode?

Tags:

php

But of course in normal mode not CLI. Formated output included among other HTML destroys existing webpage layout.

like image 680
rsk82 Avatar asked May 17 '11 19:05

rsk82


1 Answers

I just got done creating the composer library for this very purpose. Right now, it can parse the phpinfo() output when invoked from the command line, which was my use case.

Instead of using strip_tags() or any clever trick, I just worked my way backwards from everything that the original function did.

You can use the library like so:

<?php
include_once('vendor/autoload.php');

ob_start();
phpinfo();
$phpinfoAsString = ob_get_contents();
ob_get_clean();

$phpInfo = new OutCompute\PHPInfo\PHPInfo();
$phpInfo->setText($phpinfoAsString);
var_export($phpInfo->get());
?>

You can access keys within modules and elsewhere:

echo $phpInfoArray['Configuration']['bz2']['BZip2 Support']; # Will output 'Enabled' if enabled

or

echo $phpInfoArray['Thread Safety'] # Will output 'disabled' if disabled.
like image 193
kumar Avatar answered Sep 22 '22 21:09

kumar