php数组显示 phpinfo, ini, extensions等信息
1. phpinfo to array
function phpinfo_array($return=false){ ob_start(); phpinfo(-1); $pi = preg_replace( array('#^.*(.*).*$#ms', '#php license.*$#ms', '#configuration#', #\r?\n#, #(h1|h2|h3|tr)>#, '# +(?:.*?) src=(?:.*?)=(.*?) alt=php logo />' .'php version (.*?)(?:\n+?)#', '#php credits#', '#(?:.*?) src=(?:.*?)=(.*?)(?:.*?)zend engine (.*?),(?:.*?)
#', # +#, '##', '#
#'), array('$1', '', '', '', '$1>' . \n, 'php configuration'.\n.'php version $2
'. \n.'php egg $1
', 'php credits egg $1
', 'zend engine $2
' . \n . 'zend egg $1
', ' ', '%s%', '%e%'), ob_get_clean()); $sections = explode('', strip_tags($pi, '')); unset($sections[0]); $pi = array(); foreach($sections as $section) { $n = substr($section, 0, strpos($section, '')); preg_match_all('#%s%(?: (.*?) )?(?:(.*?) )?(?:(.*?) )?%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?
来源:http://php.net/parse_ini_file
?
?
?
?
?