Skip to content

Instantly share code, notes, and snippets.

@giovanniramos
Last active October 13, 2015 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save giovanniramos/4217717 to your computer and use it in GitHub Desktop.
Save giovanniramos/4217717 to your computer and use it in GitHub Desktop.
Interprets an INI file with heritage section
<?php
/**
* Interprets an INI file with heritage section
*
* @param string $filename Filename
* @return array
* @link https://gist.github.com/4217717
*
*/
function parse_ini_file_advanced($filename)
{
$nArr = array();
$oArr = parse_ini_file($filename, true);
if (is_array($oArr)) {
foreach ($oArr as $k => $v) {
$k = preg_split('~[:]~', preg_replace('~[\s]{1,}~', null, $k));
$t = &$nArr;
foreach ($k as $x) {
$t = &$t[$x];
}
$t = $v;
}
}
return $nArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment