note 111459 added to function.parse-ini-file
| From: | simon dot riget at gmail dot com | Date: | Thu, 21 Feb 2013 19:23:38 +0000 |
| Subject: | note 111459 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193718@lists.php.net to get a copy of this message | ||
.ini files or JSON file format as it is also known as, are very useful format to store stuff in.
Especially large arrays.
Strangely enough there is this nice function to read the file, but no function to write it.
So here is one.
Use it as: put_ini_file(string $file, array $array)
<?php
function put_ini_file($file, $array, $i = 0){
$str="";
foreach ($array as $k => $v){
if (is_array($v)){
$str.=str_repeat(" ",$i*2)."[$k]".PHP_EOL;
$str.=put_ini_file("",$v, $i+1);
}else
$str.=str_repeat(" ",$i*2)."$k = $v".PHP_EOL;
}
if($file)
return file_put_contents($file,$str);
else
return $str;
}
?>
----
Server IP: 69.147.83.199
Probable Submitter: 109.198.131.34
----
Manual Page -- http://php.net/manual/en/function.parse-ini-file.php
Edit -- https://master.php.net/note/edit/111459
Del: integrated -- https://master.php.net/note/delete/111459/integrated
Del: useless -- https://master.php.net/note/delete/111459/useless
Del: bad code -- https://master.php.net/note/delete/111459/bad+code
Del: spam -- https://master.php.net/note/delete/111459/spam
Del: non-english -- https://master.php.net/note/delete/111459/non-english
Del: in docs -- https://master.php.net/note/delete/111459/in+docs
Del: other reasons-- https://master.php.net/note/delete/111459
Reject -- https://master.php.net/note/reject/111459
Search -- https://master.php.net/manage/user-notes.php