note 40926 modified in function.parse-ini-file by victor

From: Date: Sat, 19 Jun 2004 15:15:59 +0000
Subject: note 40926 modified in function.parse-ini-file by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71350@lists.php.net to get a copy of this message
[Editor's note: The fwrite()-line should look like: "if (fwrite($handle, $content) === false) {" to avoid returning false when the array is empty --victor@php.net] function writeIni($assoc_arr, $path){ $content = ""; foreach ( $assoc_arr as $key=>$elem ){ $content .= "[".$key."]\n"; foreach ( $elem as $key2=>$elem2){ $content .= $key2." = \"".$elem2."\"\n"; } } if (!$handle = fopen($path, 'w')) { return false; } if (!fwrite($handle, $content)) { return false; } fclose($handle); return true; } --was-- function writeIni($assoc_arr, $path){ $content = ""; foreach ( $assoc_arr as $key=>$elem ){ $content .= "[".$key."]\n"; foreach ( $elem as $key2=>$elem2){ $content .= $key2." = \"".$elem2."\"\n"; } } if (!$handle = fopen($path, 'w')) { return false; } if (!fwrite($handle, $content)) { return false; } fclose($handle); return true; } http://php.net/manual/en/function.parse-ini-file.php

« previous php.notes (#71350) next »