note 64377 deleted from function.parse-ini-file by bjori
| From: | bjori@php.net | Date: | Thu, 13 Apr 2006 11:17:18 +0000 |
| Subject: | note 64377 deleted from function.parse-ini-file by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-107968@lists.php.net to get a copy of this message | ||
Note Submitter: hodgman at ali dot com dot au
----
If you want to use INI files as storage, you need to be able to save them, as well as load them with
parse_ini_file.
So i made this function which does the opposite of parse_ini_file. It doesnt deal with section
headings, or nested arrays, but good for saving simple data structures ;)
<?php
/**
* Saves an array as an ini-style file which can be loaded with the standard parse_ini_file
function.
*
* @param unknown_type $array Array of data to save
* @param unknown_type $filename File to save the array to
*/
function save_ini_file( $array, $filename )
{
$keys = array_keys( $array );
$fp = fopen( $filename, 'w');
foreach( $keys as $key )
{
fprintf( $fp, "%s=\"%s\"\n", $key, $array[$key] );
}
fclose( $fp );
}
?>