Parse phpinfo()

Below is ths function to parse the phpinfo() function. You can use this function to get required information from phpinfo().

Hope this is useful for you.

<?
function getPHPINIPath($strToken){
ob_start();
phpinfo(INFO_GENERAL);
$phpinfo = array('phpinfo' => array());
if(preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr>(.*?)\s*(?:(.*?)\s*(?:(.*?)\s*)?)?</tr>)#s', ob_get_clean(), $matches, PREG_SET_ORDER))
foreach($matches as $match)
if(strlen($match[1]))
$phpinfo[$match[1]] = array();
elseif(isset($match[3]))
$phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];
else
$phpinfo[end(array_keys($phpinfo))][] = $match[2];

foreach($phpinfo as $name => $section) {
foreach($section as $key => $val) {
if(is_array($val)){
//echo "11 > $key = $val[0]<br>";
}
elseif(is_string($key)){
if($key == $strToken)
return "$val";
}
else{
//echo "33 > $val<br>";
}
}
echo "\n";
}
return "";
}

echo getPHPINIDetails("System");
?>

Output: Windows NT JIVA-WKS-054 5.1 build 2600

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s