Posted By

naz on 04/27/10


Tagged

regex php apache version


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

naz


Get Apache Version and other installed software versions as associative array


 / Published in: PHP
 

this function return associative array from SERVER_SOFTWARE

  1. function getServerSoftware($key = 'SERVER_SOFTWARE')
  2. {
  3. $regex = "/(?<software>\w+)\/(?<version>[0-9.a-z]*)/";
  4.  
  5. if(isset($_SERVER[$key]) && preg_match_all($regex, $_SERVER[$key], $arr))
  6. return array_combine($arr['software'], $arr['version']);
  7. else
  8. return array();
  9. }
  10.  
  11. //USAGE EXAMPLE
  12.  
  13. //get array
  14. $serverInfo = getServerInfo();
  15.  
  16. //print apache version
  17. echo $serverInfo['Apache'];
  18.  
  19. //print all information
  20. foreach($serverInfo as $software=>$version) echo "{$software}: {$version}<br>\n";

Report this snippet  

You need to login to post a comment.