note 91623 added to function.parse-ini-file

From: Date: Fri, 19 Jun 2009 21:11:53 +0000
Subject: note 91623 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-157143@lists.php.net to get a copy of this message
Here is an adaption of Jomel's write_ini_file function to support arrays and eliminate redundant speechmarking on NULL values 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; } } ---- Server IP: 209.41.74.194 Probable Submitter: 82.22.199.204 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/91623 Del: integrated -- https://master.php.net/note/delete/91623/integrated Del: useless -- https://master.php.net/note/delete/91623/useless Del: bad code -- https://master.php.net/note/delete/91623/bad+code Del: spam -- https://master.php.net/note/delete/91623/spam Del: non-english -- https://master.php.net/note/delete/91623/non-english Del: in docs -- https://master.php.net/note/delete/91623/in+docs Del: other reasons-- https://master.php.net/note/delete/91623 Reject -- https://master.php.net/note/reject/91623 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157143) next »