如何将phpinfo()的输出获取为xml?
有没有办法做到这一点 我发现这个函数:如何将phpinfo()的输出获取为xml?,php,xml,Php,Xml,有没有办法做到这一点 我发现这个函数: function phpinfo_array($return=true){ /* Andale! Andale! Yee-Hah! */ ob_start(); phpinfo(-1); $pi = preg_replace( array('#^.*<body>(.*)</body>.*$#ms',
function phpinfo_array($return=true){
/* Andale! Andale! Yee-Hah! */
ob_start();
phpinfo(-1);
$pi = preg_replace(
array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
'#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
"#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%',
'#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
.'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
'#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
'#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
"# +#", '#<tr>#', '#</tr>#'),
array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
'<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'.
"\n".'<tr><td>PHP Egg</td><td>$1</td></tr>',
'<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
'<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
'<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'),
ob_get_clean());
$sections = explode('<h2>', strip_tags($pi, '<h2><th><td>'));
unset($sections[0]);
$pi = array();
foreach($sections as $section){
$n = substr($section, 0, strpos($section, '</h2>'));
preg_match_all(
'#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#',
$section, $askapache, PREG_SET_ORDER);
foreach($askapache as $m)
$pi[$n][$m[1]]=(!isset($m[3])||@$m[2]==$m[3])?@$m[2]:array_slice($m,2);
}
return ($return === false) ? print_r($pi) : $pi;
函数phpinfo_数组($return=true){
/*安代尔!安代尔!耶哈*/
ob_start();
phpinfo(-1);
$pi=预更换(
数组(“#^.*(.*)。*$#ms',“#PHP许可证。*$#ms',
“#配置#”、“#\r?\n#”、“##”、“#+”、“#+看起来函数将返回一个数组 通过遍历数组并添加键和值,可以轻松地将其转换为xml
有一些很好的答案。您找到了一个函数,就这样?您的问题是什么?尝试时发生了什么?您得到了错误的结果吗?没有得到结果吗?什么不起作用?请解释。我认为HTML DOM解析器可能能够实现这一点(将HTML导出为XML)。