当前位置: 代码迷 >> PHP >> PHP数组展示 phpinfo, ini, extensions等信息
  详细解决方案

PHP数组展示 phpinfo, ini, extensions等信息

热度:803   发布时间:2013-12-20 17:03:19.0
PHP数组显示 phpinfo, ini, extensions等信息

1. phpinfo to array

function phpinfo_array($return=false)
{
 	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;
}

phpinfo_array();

?

来源:http://www.php.net/manual/en/function.phpinfo.php#87463

?

2. get_loaded_extensions? and PHP_VERSION

print_r(get_loaded_extensions());  

//print_r(apache_get_modules()); // 一般服务商都会屏蔽掉

print_r(PHP_VERSION);

?

3.? ini to array

$ini_path = php_ini_loaded_file();
print_r($ini_path); 

$ini = parse_ini_file($ini_path);
print_r($ini);

?

or

function parse_ini ( $filepath ) 
{
    $ini = file( $filepath );
    if ( count( $ini ) == 0 ) { return array(); }
    $sections = array();
    $values = array();
    $globals = array();
    $i = 0;
    foreach( $ini as $line ){
        $line = trim( $line );
        // Comments
        if ( $line == '' || $line{0} == ';' ) { continue; }
        // Sections
        if ( $line{0} == '[' ) {
            $sections[] = substr( $line, 1, -1 );
            $i++;
            continue;
        }
        // Key-value pair
        list( $key, $value ) = explode( '=', $line, 2 );
        $key = trim( $key );
        $value = trim( $value );
        if ( $i == 0 ) {
            // Array values
            if ( substr( $line, -1, 2 ) == '[]' ) {
                $globals[ $key ][] = $value;
            } else {
                $globals[ $key ] = $value;
            }
        } else {
            // Array values
            if ( substr( $line, -1, 2 ) == '[]' ) {
                $values[ $i - 1 ][ $key ][] = $value;
            } else {
                $values[ $i - 1 ][ $key ] = $value;
            }
        }
    }
    for( $j=0; $j<$i; $j++ ) {
        $result[ $sections[ $j ] ] = $values[ $j ];
    }
    return $result + $globals;
}

//$stores = parse_ini($ini_path);
//print_r( $stores );

?

来源:http://php.net/parse_ini_file

?

?

?

?

?

  相关解决方案