note 86410 added to function.parse-ini-file

From: Date: Fri, 17 Oct 2008 02:47:41 +0000
Subject: note 86410 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-145444@lists.php.net to get a copy of this message
Working on a project for a client recently, I needed a way to set a default configuration INI file, but also wanted to allow the client to override the settings through the use of a custom INI file. I thought array_merge or array_merge_recursive would do the trick for me, but it fails to override settings in the way that I wanted. I wrote my own function to do what I wanted. It's nothing spectacular, but thought I'd post it here in case it saved someone else some time. <?php function ini_merge ($config_ini, $custom_ini) { foreach ($custom_ini AS $k => $v): if (is_array($v)): $config_ini[$k] = ini_merge($config_ini[$k], $custom_ini[$k]); else: $config_ini[$k] = $v; endif; endforeach; return $config_ini; }; $CONFIG_INI = parse_ini_file('../config.ini', TRUE); $CUSTOM_INI = parse_ini_file('ini/custom.ini', TRUE); $INI = ini_merge($CONFIG_INI, $CUSTOM_INI); ?> This allowed me to put the default INI file above the web root with information that requires extra security (database connection info, etc.) and a writable INI file within the structure of the site without affecting the default settings of the default config.ini file. Anyway, hope it helps. ---- Server IP: 69.147.83.197 Probable Submitter: 72.192.51.154 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/86410 Del: integrated -- https://master.php.net/note/delete/86410/integrated Del: useless -- https://master.php.net/note/delete/86410/useless Del: bad code -- https://master.php.net/note/delete/86410/bad+code Del: spam -- https://master.php.net/note/delete/86410/spam Del: non-english -- https://master.php.net/note/delete/86410/non-english Del: in docs -- https://master.php.net/note/delete/86410/in+docs Del: other reasons-- https://master.php.net/note/delete/86410 Reject -- https://master.php.net/note/reject/86410 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145444) next »