EvilZone

Programming and Scripting => Web Oriented Coding => : bubzuru October 06, 2013, 04:39:00 PM

: [Request] Edit INI File ?
: 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 ?
: Re: [Request] Edit INI File ?
: ca0s October 06, 2013, 05:22:08 PM
asd.ini
:
[first]
foo = "bar"
asd = "fgh"
number = 1

[second]
herp = "derp"
lol = "wut"

ini.php
: (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;
}
?>

: Re: [Request] Edit INI File ?
: bubzuru October 06, 2013, 05:36:43 PM
thank you +1

when you use ($content as $var => $value) what does the => do
maybe its a stupid question but i suck at php
: Re: [Request] Edit INI File ?
: ca0s October 06, 2013, 05:42:40 PM
:
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.
: Re: [Request] Edit INI File ?
: bubzuru October 06, 2013, 05:59:33 PM
:
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
: Re: [Request] Edit INI File ?
: ca0s October 06, 2013, 06:05:18 PM
You're welcome