note 84259 added to function.phpinfo
| From: | jon at sitewizard dot ca | Date: | Sun, 06 Jul 2008 02:54:57 +0000 |
| Subject: | note 84259 added to function.phpinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141211@lists.php.net to get a copy of this message | ||
To extract all of the data from phpinfo into a nested array:
<?php
ob_start();
phpinfo();
$phpinfo = array('phpinfo' => array());
if(preg_match_all('#(?:<h2>(?:<a
name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?:
class=".*?")?><t[hd](?:
class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?:
class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?:
class=".*?")?>(.*?)\s*</t[hd]>)?)?</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];
?>
Some examples of using individual values from the array:
<?php
echo "System: {$phpinfo['phpinfo']['System']}<br />\n";
echo "Safe Mode: {$phpinfo['PHP Core']['safe_mode'][0]}<br
/>\n";
echo "License: {$phpinfo['PHP License'][0]}<br />\n";
?>
To display everything:
<?php
foreach($phpinfo as $name => $section) {
echo "<h3>$name</h3>\n<table>\n";
foreach($section as $key => $val) {
if(is_array($val))
echo
"<tr><td>$key</td><td>$val[0]</td><td>$val[1]</td></tr>\n";
elseif(is_string($key))
echo "<tr><td>$key</td><td>$val</td></tr>\n";
else
echo "<tr><td>$val</td></tr>\n";
}
echo "</table>\n";
}
?>
Note: In order to properly retrieve all of the data, the regular expression matches table headers as
well as table data, resulting in 'Local Value' and 'Global Value' showing up as
'Directive' entries.
----
Server IP: 66.207.199.35
Probable Submitter: 74.127.214.180
----
Manual Page -- http://www.php.net/manual/en/function.phpinfo.php
Edit -- https://master.php.net/note/edit/84259
Del: integrated -- https://master.php.net/note/delete/84259/integrated
Del: useless -- https://master.php.net/note/delete/84259/useless
Del: bad code -- https://master.php.net/note/delete/84259/bad+code
Del: spam -- https://master.php.net/note/delete/84259/spam
Del: non-english -- https://master.php.net/note/delete/84259/non-english
Del: in docs -- https://master.php.net/note/delete/84259/in+docs
Del: other reasons-- https://master.php.net/note/delete/84259
Reject -- https://master.php.net/note/reject/84259
Search -- https://master.php.net/manage/user-notes.php