note 94414 added to function.parse-ini-file

From: Date: Tue, 03 Nov 2009 16:38:37 +0000
Subject: note 94414 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-162369@lists.php.net to get a copy of this message
Didnt find the one,which suits my needs,so Heres a small and easy write ini from array function... Maybe you`ll find it handy. <?php function write_php_ini($array, $file) { $res = array(); foreach($array as $key => $val) { if(is_array($val)) { $res[] = "[$key]"; foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"'); } else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"'); } safefilerewrite($file, implode("\r\n", $res)); } ////// function safefilerewrite($fileName, $dataToSave) { if ($fp = fopen($fileName, 'w')) { $startTime = microtime(); do { $canWrite = flock($fp, LOCK_EX); // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load if(!$canWrite) usleep(round(rand(0, 100)*1000)); } while ((!$canWrite)and((microtime()-$startTime) < 1000)); //file was locked so now we can store information if ($canWrite) { fwrite($fp, $dataToSave); flock($fp, LOCK_UN); } fclose($fp); } } ?> ---- Server IP: 195.222.16.155 Probable Submitter: ::ffff:193.40.244.203 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/94414 Del: integrated -- https://master.php.net/note/delete/94414/integrated Del: useless -- https://master.php.net/note/delete/94414/useless Del: bad code -- https://master.php.net/note/delete/94414/bad+code Del: spam -- https://master.php.net/note/delete/94414/spam Del: non-english -- https://master.php.net/note/delete/94414/non-english Del: in docs -- https://master.php.net/note/delete/94414/in+docs Del: other reasons-- https://master.php.net/note/delete/94414 Reject -- https://master.php.net/note/reject/94414 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162369) next »