note 56710 deleted from function.parse-ini-file by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 17:13:26 +0000 |
| Subject: | note 56710 deleted from function.parse-ini-file by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176165@lists.php.net to get a copy of this message | ||
Note Submitter: wickedfather at hotmail dot com
----
Slight modification of write_ini_file that will keep values global in an array if they appear after
an array
<?php function write_ini_file($path, $assoc_array)
{
$content = '';
$sections = '';
foreach ($assoc_array as $key => $item)
{
if (is_array($item))
{
$sections .= "\n[{$key}]\n";
foreach ($item as $key2 => $item2)
{
if (is_numeric($item2) || is_bool($item2))
$sections .= "{$key2} = {$item2}\n";
else
$sections .= "{$key2} = \"{$item2}\"\n";
}
}
else
{
if(is_numeric($item) || is_bool($item))
$content .= "{$key} = {$item}\n";
else
$content .= "{$key} = \"{$item}\"\n";
}
}
$content .= $sections;
if (!$handle = fopen($path, 'w'))
{
return false;
}
if (!fwrite($handle, $content))
{
return false;
}
fclose($handle);
return true;
} ?>