Heim  >  Artikel  >  Backend-Entwicklung  >  PHP数组展示 phpinfo, ini, extensions等信息

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

WBOY
WBOYOriginal
2016-06-13 11:43:09769Durchsuche

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

1. phpinfo to array

function phpinfo_array($return=false){ 	ob_start(); 	phpinfo(-1);  	$pi = preg_replace( 	array('#^.*(.*).*$#ms', '#<h2>PHP License</h2>.*$#ms',	 '#<h1>Configuration</h1>#',  "#\r?\n#", "#(h1|h2|h3|tr)>#", '# +(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" />'	  .'<h1>PHP Version (.*?)</h1>(?:\n+?)#',	  '#<h1><a href="(?:.*?)%5C?=(.*?)">PHP Credits</a></h1>#',	  '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',	  "# +#", '#<tr>#', '#</tr>#'), 	array('$1', '', '', '', '$1>' . "\n", 'PHP Configuration'."\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></th>
<td>')); 	unset($sections[0]); 	$pi = array(); 	foreach($sections as $section) 	{   		$n = substr($section, 0, strpos($section, ''));   		preg_match_all('#%S%(?:</td>
<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();</h2>
</h2>

?

来源: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<p>?</p><p>来源:http://php.net/parse_ini_file</p><p>?</p><p>?</p><p>?</p><p>?</p><p>?</p><div class="clear">
                 
              
              
        
            </div>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn