EvilZone
Programming and Scripting => Web Oriented Coding => : bubzuru October 06, 2013, 04:39:00 PM
-
im using parse_ini_file to grab and sort the ini file into an array
now how do i write that array back to file ? does php have any functions for that ?
-
asd.ini
[first]
foo = "bar"
asd = "fgh"
number = 1
[second]
herp = "derp"
lol = "wut"
ini.php
<?php
$conf = parse_ini_file("asd.ini", true);
write_ini_file($conf, "test.ini", true);
function write_ini_file($conf, $file, $sections=false)
{
$fd = fopen($file, "w");
if($fd !== false) {
foreach($conf as $name => $content) {
if($sections===true) {
fwrite($fd, "[".$name."]\n");
foreach($content as $var => $value) {
fwrite($fd, $var ." = ". $value . "\n");
}
} else {
fwrite($fd, $name ." = ".$content ."\n");
}
}
fclose($fd);
return true;
}
return false;
}
?>
-
thank you +1
when you use ($content as $var => $value) what does the => do
maybe its a stupid question but i suck at php
-
http://php.net/manual/en/language.types.array.php
It means that $content is an array which contains certain number of key => value pairs. With "foreach($content as $var => $value)", I'm taking every element of the $content array, and getting it's key and value.
-
http://php.net/manual/en/language.types.array.php
It means that $content is an array which contains certain number of key => value pairs. With "foreach($content as $var => $value)", I'm taking every element of the $content array, and getting it's key and value.
ahh now i get it, thank you
-
You're welcome