<?
function writeINIfile ($filename, $array1, $commentchar, $commenttext) {
$
handle = fopen($filename, 'wb');
if ($commenttext!='') {
$comtext = $commentchar.
str_replace($commentchar, "\r\n".$commentchar,
str_replace ("\r", $commentchar,
str_replace("\n", $commentchar,
str_replace("\n\r", $commentchar,
str_replace("\r\n", $commentchar, $commenttext)
)
)
)
)
;
if (substr($comtext, -1, 1)==$commentchar && substr($commenttext, -1, 1)!=$commentchar) {
$comtext = substr($comtext, 0, -1);
}
fwrite ($
handle, $comtext."\r\n");
}
foreach ($array1 as $sections => $items) {
//Write the section
if (isset($section)) { fwrite ($
handle, "\r\n"); }
//$section = ucfirst(preg_replace('/[\0-\37]|[\177-\377]/', "-", $sections));
$section = ucfirst(preg_replace('/[\0-\37]|\177/', "-", $sections));
fwrite ($
handle, "[".$section."]\r\n");
foreach ($items as $keys => $values) {
//Write the key/value pairs
//$key = ucfirst(preg_replace('/[\0-\37]|=|[\177-\377]/', "-", $keys));
$key = ucfirst(preg_replace('/[\0-\37]|=|\177/', "-", $keys));
if (substr($key, 0, 1)==$commentchar) { $key = '-'.substr($key, 1); }
$value = ucfirst(addcslashes($values,''));
fwrite ($
handle, ' '.$key.' = "'.$value."\"\r\n");
}
}
fclose($
handle);
}
?>