note 64377 added to function.parse-ini-file
| From: | hodgman at ali dot com dot au | Date: | Thu, 13 Apr 2006 04:33:35 +0000 |
| Subject: | note 64377 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107954@lists.php.net to get a copy of this message | ||
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 );
}
?>
----
Server IP: 203.220.0.234
Probable Submitter: 203.2.182.254 (proxied: 1.1 AURB-PROXY-03)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php
Edit -- http://master.php.net/note/edit/64377
Del: integrated -- http://master.php.net/note/delete/64377/integrated
Del: useless -- http://master.php.net/note/delete/64377/useless
Del: bad code -- http://master.php.net/note/delete/64377/bad+code
Del: spam -- http://master.php.net/note/delete/64377/spam
Del: non-english -- http://master.php.net/note/delete/64377/non-english
Del: in docs -- http://master.php.net/note/delete/64377/in+docs
Del: other reasons-- http://master.php.net/note/delete/64377
Reject -- http://master.php.net/note/reject/64377
Search -- http://master.php.net/manage/user-notes.php