note 44519 deleted from function.parse-ini-file by danbrown

From: Date: Sun, 23 Jan 2011 17:17:15 +0000
Subject: note 44519 deleted from function.parse-ini-file by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176178@lists.php.net to get a copy of this message
Note Submitter: tomasz.frelik(at)enzo.pl ---- Here is a better version of write_ini_file() function, which can found below. This version allows you to use sections and still have "global" variables in ini file. The structure of resulting ini file mirrors the structure of the array passed to the function. You can have sections or no, it's up to you. function write_ini_file($path, $assoc_array) { foreach ($assoc_array as $key => $item) { if (is_array($item)) { $content .= "\n[$key]\n"; foreach ($item as $key2 => $item2) { $content .= "$key2 = \"$item2\"\n"; } } else { $content .= "$key = \"$item\"\n"; } } if (!$handle = fopen($path, 'w')) { return false; } if (!fwrite($handle, $content)) { return false; } fclose($handle); return true; }

« previous php.notes (#176178) next »