0

Is there a way to achieve this?

I found this function:

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]+#", '#&nbsp;#', '#  +#', '# class=".*?"#', '%&#039;%',
              '#<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;

}

This function returns an array with the data from phpinfo() which looks quite like a hammer-method ;)

But it seems, like phpinfo() provides data that are not to achieve otherwisee.

Now how can I correctly turn this complicated array into valid XML?

rubo77
  • 19,527
  • 31
  • 134
  • 226
  • 3
    You found a function and that's it? What is your question? What happened when you tried it? Did you get incorrect results? Did you get *no* results? What doesn't work? Please explain. – Amal Murali Feb 13 '14 at 13:09
  • I think HTML DOM Parser might be able to achive this (export HTML as XML). – gskema Feb 13 '14 at 13:12

1 Answers1

0

It looks like your function will return an array.

You can easily turn this into an xml using SimpleXMLElement, by walking through your array and adding the keys and values.

There are some nice answers here.

Community
  • 1
  • 1
Loopo
  • 2,204
  • 2
  • 28
  • 45