RE: [PHP] reading file into a keyword-indexed array
| From: | John W. Holmes | Date: | Wed, 05 Feb 2003 00:46:27 +0000 |
| Subject: | RE: [PHP] reading file into a keyword-indexed array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134353@lists.php.net to get a copy of this message | ||
> I would like to read and write user-settings to a keyword-value file
and
> be
> able to extract it. The following code works fine but i wondered if
there
> was a more elegant/direct way of doing this.
For reading, parse_ini_file() is elegant and direct.
Writing is another matter. If you are getting your data through a form,
you can loop through the $_POST array and write key=>value pairs to the
file that can later be read by parse_ini_file().
I've got a small class that will read a php.ini style file and convert
all of the variable=value pairs into form elements. It'll take the
submitted form and re-write the .ini file with whatever you submit. You
could probably adapt that to your needs. Email me offlist if you want a
copy.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/