Skip to content

Instantly share code, notes, and snippets.

@dre1080
Created May 24, 2011 10:27
Show Gist options
  • Save dre1080/988488 to your computer and use it in GitHub Desktop.
Save dre1080/988488 to your computer and use it in GitHub Desktop.
Simple ini parser
$debug = function($var, $exit = true) {
echo '<pre>';
(is_array($var) || is_object($var)) ? print_r($var) : var_dump($var);
echo '</pre>';
if ($exit)
exit;
};
$parse = function($file, $show_debug = false) use ($debug) {
$ini = parse_ini_file($file);
if ($show_debug)
$debug($ini, false);
foreach ($ini as $key => $val) {
foreach ($ini as $k => $v) {
$ini[$k] = str_replace("[$key]", $val, $v);
}
}
$obj = (object)$ini;
unset($ini);
if ($show_debug)
$debug($obj);
return $obj;
};
// Usage
$c = $parse('database.ini', true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment