Location: PHPKode > scripts > PHP Requirements Checker > reqchecker/check.php
<?
/*******************************************************************************
 * Copyright (c) 2005-2012 I-Ween (http://i-ween.com).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Alexey Furmanov - Initial API and implementation
 * Special thanx to:
 *    Ken - phpinfo() parsing
 *    AlterVega - some ideas
 *    Alexander Gurov - for the expert opinion    
 *******************************************************************************/
include_once 'addons.php';
$lang = 'en';//change to ru for russian
$reqs = getRequirements($lang);
$info = phpinfo_array(INFO_MODULES);
$result = checkRequirements( $reqs, $info );
?>
<!DOCTYPE html 
	     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title><?echo (string) $reqs->title;?></title>
	<style type='text/css'>
		.pass {
			color: green;
			font-weight: bold;
		}
		
		.fail {
			color: red;
			font-weight: bold;
		}

		p {
			margin: 2px;
			padding: 4px;
			border-bottom: 1px dotted grey;
			font-size: 15px;
			font-family: "Arial, Verdana";
		}
		
		h1 {
			border-bottom: 1px solid black;
		}
		h2 {
			border-bottom: 1px dotted black;
		}
	</style>
	
</head>
<body>
	<h1><?echo (string) $reqs->title;?></h1>
<?
$flag = true;
foreach( $result as $group )
{
  echo "<h2>$group[0]</h2>";
  foreach( $group[1] as $item )
  {
      $flag &= $item[3];
      echo "<p> {$item[0]}: <span class=\"" . ($item[3]?'pass':'fail') . "\">{$item[2]}". ($item[1]?(" (" . ($item[3]?'&ge;':'<') . "{$item[1]})"):'')."</span></p>";
  }
}
if ($flag)
{
    echo '<input type="button" value="'.(string) $reqs->resource['continue_install'].'" onClick="window.location.href=\''. (string) $reqs->success_url.'\'">'; 
}
else
{
    echo '<input type="button" value="'.(string) $reqs->resource['try_again'].'" onClick="window.location.reload()">'; 
}
?>
</body>
</html>

<?
function checkRequirements( $xml, $info )
{
  $result = array();
  foreach( $xml->group as $group )
  {
      $gres = array($group->description);
      $items = array();
      foreach ($group->item as $item)
      {
          $it = array();
          //description
          $it[0] = (string) $item->description. " / {$item['name']}";

          //needed value
          $reqval = (string) $item->version?(string) $item->version:(string) $item->value;

          //actual value
          if ((string) $item->getter)
          {
              $actval = call_user_func((string) $item->getter);
          }
          if ((string) $group['type'] == 'settings')
          {
              $actval = ini_get($item['name']);
          }
          if ((string) $group['type'] == 'libraries' || (string)$item->key)
          {
              $actval = (string)$item->key? $info[(string) $item['name']][(string) $item->key]:null;
          }

          $it[1] = $reqval;
          $it[2] = $actval;

          //data preparing for compare
          if ((string) $item->pattern)
          {
              preg_match( (string) $item->pattern, $actval, $matches);
              $actval = $matches[1];
          }

          if ((string) $item->clean_pattern)
          {
              $reqval = preg_replace( (string) $item->clean_pattern, '', $reqval);
              $actval = preg_replace( (string) $item->clean_pattern, '', $actval);
          }

          //function call for checking
          if ((string) $item->checker)
          {
             $it[3] = call_user_func((string) $item->checker, $reqval);
             $it[2] = $it[3] ? ((string) $xml->resource['passed']) : ((string)$xml->resource['rejected']);
          }
          //version checking
          elseif ((string) $item->version)
          {
            $it[3] = version_compare($actval, $reqval) >= 0;
          }
          //number values checking
          elseif ((string) $item->value)
          {
            $it[3] = $actval >= $reqval;
          }
          elseif ((string) $group['type'] == 'libraries')
          {
            $it[3] = isset($info[(string) $item['name']]);
            $it[2] = $it[3]?$xml->resource['installed']:$xml->resource['not_installed'];
          }

          $items[] = $it;
      }

      $gres[] = $items;
      $result[] = $gres;
  }

	return $result;
}

function getRequirements($lang = 'en')
{
	$xml = simplexml_load_file( dirname(__FILE__) . "/requirements_$lang.xml" );
	return $xml;
}

function phpinfo_array($what=INFO_ALL)
{
    ob_start();
    phpinfo($what);
    $info_arr = array();
    $info_lines = explode("\n", strip_tags(ob_get_clean(), "<tr><td><h2>"));
    $cat = "General";
    foreach($info_lines as $line)
    {
        // new cat?
        preg_match("~<h2>(.*)</h2>~", $line, $title) ? $cat = $title[1] : null;
        if(preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val))
        {
            $info_arr[$cat][trim($val[1])] = trim($val[2]);
        }
        elseif(preg_match("~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val))
        {
            $info_arr[$cat][trim($val[1])] = array("local" => $val[2], "master" => $val[3]);
        }
    }
    return $info_arr;
}
?>
Return current item: PHP Requirements Checker