Author Topic: [Request] Edit INI File ?  (Read 1060 times)

0 Members and 1 Guest are viewing this topic.

Offline bubzuru

  • Knight
  • **
  • Posts: 395
  • Cookies: 21
  • everything is contained in the data
    • View Profile
    • New School Tools
[Request] Edit INI File ?
« on: 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 ?
Damm it feels good to be gangsta
http://bubzuru.comule.com

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [Request] Edit INI File ?
« Reply #1 on: October 06, 2013, 05:22:08 pm »
asd.ini
Code: [Select]
[first]
foo = "bar"
asd = "fgh"
number = 1

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

ini.php
Code: (php) [Select]
<?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;
}
?>


Offline bubzuru

  • Knight
  • **
  • Posts: 395
  • Cookies: 21
  • everything is contained in the data
    • View Profile
    • New School Tools
Re: [Request] Edit INI File ?
« Reply #2 on: 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
Damm it feels good to be gangsta
http://bubzuru.comule.com

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [Request] Edit INI File ?
« Reply #3 on: October 06, 2013, 05:42:40 pm »
Code: [Select]
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.

Offline bubzuru

  • Knight
  • **
  • Posts: 395
  • Cookies: 21
  • everything is contained in the data
    • View Profile
    • New School Tools
Re: [Request] Edit INI File ?
« Reply #4 on: October 06, 2013, 05:59:33 pm »
Code: [Select]
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
Damm it feels good to be gangsta
http://bubzuru.comule.com

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [Request] Edit INI File ?
« Reply #5 on: October 06, 2013, 06:05:18 pm »
You're welcome