This core function won't handle ini key[][] = value(s), (multidimensional arrays), so if you need to support that kind of setup you will need to write your own function. one way to do it is to convert all the key = value(s) to array string [key][][]=value(s), then use parse_str() to convert all those [key][][]=value(s) that way you just read the ini file line by line, instead of doing crazy foreach() loops to handle those (multidimensional arrays) in each section, example...
ini file...... config.php
<?php
; This is a sample configuration file
; Comments start with ';', as in php.ini
[first_section]
one = 1
five = 5
animal = BIRD
[second_section]
path = "/usr/local/bin"
URL = "http://www.example.com/~username"
[third_section]
phpversion[] = "5.0"
phpversion[] = "5.1"
phpversion[] = "5.2"
phpversion[] = "5.3"
urls[svn] = "http://svn.php.net"
urls[git] = "http://git.php.net"
[fourth_section]
a[][][] = b
a[][][][] = c
a[test_test][][] = d
test[one][two][three] = true
?>
echo parse_ini_file ( "C:\\services\\www\\docs\\config.php" );
results in...
// PHP Warning: syntax error, unexpected TC_SECTION, expecting '=' line 27 -> a[][][] = b
Here it simple function that handles (multidimensional arrays) without looping each key[][]= value(s)
<?php
function getIni ( $file, $sections = FALSE )
{
$return = array ();
$keeper = array ();
$config = fopen ( $file, 'r' );
while ( ! feof ( $config ) )
{
$line = trim ( fgets ( $config, 1024 ) );
$line = ( $line == '' ) ? ' ' : $line;
switch ( $line{0} )
{
case ' ':
case '#':
case '/':
case ';':
case '<':
case '?':
break;
case '[':
if ( $sections )
{
$header = 'config[' . trim ( substr ( $line, 1, -1 ) ) . ']';
}
else
{
$header = 'config';
}
break;
default:
$kv = array_map ( 'trim', explode ( '=', $line ) );
$kv[0] = str_replace ( ' ', '+', $kv[0] );
$kv[1] = str_replace ( ' ', '+', $kv[1] );
if ( ( $pos = strpos ( $kv[0], '[' ) ) !== FALSE )
{
$kv[0] = '[' . substr ( $kv[0], 0, $pos ) . ']' . substr ( $kv[0], $pos );
}
else
{
$kv[0] = '[' . $kv[0] . ']';
}
$bt = strtolower ( $kv[1] );
if ( in_array ( $bt, array ( 'true', 'false', 'on', 'off' ) ) )
{
$kv[1] = ( $bt == 'true' || $bt == 'on' ) ? TRUE : FALSE;
}
$keeper[] = $header . $kv[0] . '=' . $kv[1];
}
}
fclose ( $config );
parse_str ( implode ( '&', $keeper ), $return );
return $return['config'];
}
// usage...
$sections = TRUE;
print_r ( $config->getIni ( "C:\\services\\www\\docs\\config.php" ), $sections );
?>