Hello! I'm creating a larger scale application in PHP and i'm using a .ini file to store some configuration for the user, quite easy to fetch data with the parse_ini_file function (returns array) but how would I write to a ini file, or the most convienient way to do so. That is needed because I am created a installer wizard type of thing and an admin panel, so it would be nice to write to the configuration file. Thanks for any help!

Member Avatar for LastMitch

@NardCake

Hello! I'm creating a larger scale application in PHP and i'm using a .ini file to store some configuration for the user, quite easy to fetch data with the parse_ini_file function (returns array) but how would I write to a ini file, or the most convienient way to do so. That is needed because I am created a installer wizard type of thing and an admin panel, so it would be nice to write to the configuration file. Thanks for any help!

The question you ask is a bit broad or very general. What you do want to do?

Here is a list of directives and the parse_ini_file function:

http://php.net/manual/en/ini.list.php

http://php.net/manual/en/function.parse-ini-file.php

It provide a examples that you can used.

If you have a code that you are working on.

It would be nice if you can post what you have so far, so we can have a better idea what you want to do.

Basically, I have an application the reads a pre-existing "config.ini" file. I want to write a 'installer' for my application so the user can easily insert data into the fields and it will write or edit the configuration file (config.ini). Say for example this is my ini file.

admin_email=admin@example.com
admin_username=ADMIN 
admin_password=password 

Now in my installation it would ask for those fields, and I want to write or edit the file so it contains what the user specified, so for example it would now be

admin_email=mynewemail@example.com
admin_username=MyNewUsername
admin_password=MyNewPassWord

Hopefully that clears it up. And thanks I will browse through those links and try to find something. Thanks!
--Edit--
And just to make this clear this has nothing to do with php.ini.

Member Avatar for LastMitch

And just to make this clear this has nothing to do with php.ini.

The ini file is part of PHP. Unless you didn't explain it very clearly on what you want to do with the ini file.

The parse_ini_file() function can help you update/create configuration files by writing the whole config.ini file. Read/parse the existing settings into a php array. Then it will set any of the array elements with values/new values, then write the whole config.ini file based on that array of settings.

I hope that make sense. If not then can you explain little more in detail. I know you provide a small code but it would be easier if you can explain more.

Alright thanks for the info, I will look through all of this interesting information. Thanks again! (both of you)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.