0

right now I'm doing it this way:

$myFile = "config.ini";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "[scripts]\n\n[admin]\nhide_fields[] = ctr_ad_headerImg\n\n";
fwrite($fh, $stringData);
$stringData = "[widget_areas]\n0.name = \"Top Navigation\"\n0.id = top-nav\n0.description = \"Widget area at the very top of the page\"\n\n[default_colors]\nsitebg = #$sitebg\nfooterbg = #$footerbg\nlink = #$link\nurl = #$url\nbg = #$bg\ntext = #$text\nborder = #$border\n\nlu_link = #$lu_link\nlu_url = #$lu_url\nlu_bg = #$lu_bg\nlu_text = #$lu_text\nlu_border = #$lu_border";
fwrite($fh, $stringData);
fclose($fh);

The problem here is that I have to keep that exact file structure, what is a better way to do this? What should I study ? Any tutorials? Thanks

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
Joricam
  • 2,329
  • 4
  • 18
  • 14
  • Just a suggestion/not answer: If you're looking to keep a specific/exact file structure, you might wanna consider (changing to) saving files as xml instead (that way you can use existing markup instead of inventing your own). If you do that, you also might be better off in the long run considering xml is very widely used (increasing compatibility). This is a good place to get started if you're interested: http://php.net/manual/en/book.simplexml.php – PiZzL3 Apr 16 '11 at 21:40

1 Answers1

0

To write an ini file, I would recommend using php's built in ini parser: http://php.net/manual/en/function.parse-ini-file.php
And then create ini file, write values in PHP to write the array back to the file.

Community
  • 1
  • 1
Jess
  • 8,628
  • 6
  • 49
  • 67
  • but I need a more broader aproach, so I can stipulate the file format myself and how it is written in it – Joricam Apr 16 '11 at 20:46