Hi,
I want to create this configurable file. But the configuration will be made from external systems.
So except for parsing the content for using it.....I should also be able to modify it.
I see parse_ini_file parses the file pretty good...and I can easily use such structure of the file.
My question is is there any easy way to modify the data and save the contents back to the file keeping this structure.
Thanks in advance
[solved]Using php_parse_ini and saving afterwards
Moderator: General Moderators
[solved]Using php_parse_ini and saving afterwards
Last edited by jmut on Wed Nov 16, 2005 9:18 am, edited 1 time in total.
look no further than the comments by tomasz.frelik(at)enzo.pl for parse_ini_file()
Code: Select all
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;
}