note 91623 deleted from function.parse-ini-file by danbrown

From: Date: Sun, 23 Jan 2011 17:08:01 +0000
Subject: note 91623 deleted from function.parse-ini-file by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176151@lists.php.net to get a copy of this message
Note Submitter: DDRKhat ---- Here is an adaption of Jomel's write_ini_file function to support arrays and eliminate redundant speechmarking on NULL values <?php if (!function_exists('write_ini_file')) { function write_ini_file($assoc_arr, $path, $has_sections=FALSE) { $content = ""; if ($has_sections) { foreach ($assoc_arr as $key=>$elem) { $content .= "[".$key."]\n"; foreach ($elem as $key2=>$elem2) { if(is_array($elem2)) { for($i=0;$i<count($elem2);$i++) { $content .= $key2."[] = \"".$elem2[$i]."\"\n"; } } else if($elem2=="") $content .= $key2." = \n"; else $content .= $key2." = \"".$elem2."\"\n"; } } } else { foreach ($assoc_arr as $key=>$elem) { if(is_array($elem)) { for($i=0;$i<count($elem);$i++) { $content .= $key2."[] = \"".$elem[$i]."\"\n"; } } else if($elem=="") $content .= $key2." = \n"; else $content .= $key2." = \"".$elem."\"\n"; } } if (!$handle = fopen($path, 'w')) { return false; } if (!fwrite($handle, $content)) { return false; } fclose($handle); return true; } } ?>

« previous php.notes (#176151) next »