note 44519 added to function.parse-ini-file
| From: | (at) | Date: | Sun, 08 Aug 2004 23:49:59 +0000 |
| Subject: | note 44519 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74262@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44519
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44519&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44519&report=yes
Search -- http://master.php.net/manage/user-notes.php