note 75356 deleted from function.parse-ini-file by cmb
| From: | cmb@php.net | Date: | Sun, 02 Dec 2018 12:50:01 +0000 |
| Subject: | note 75356 deleted from function.parse-ini-file by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209828@lists.php.net to get a copy of this message | ||
Note Submitter: Mildred
----
I wrote few functions to work with ini files.
The function make_ini_file($array, &$errors)
The function read_ini($file)
The function prepare_ini($array, $maxdepth=NULL)
The function prepare_ini($array, $maxdepth=NULL)
This function will take an array as returned by the function read_ini() and will return an array as
needed by the function make_ini_file() so that you can write extanded ini files easily.
If maxdepth is not given (or if maxdepth is NULL), this function will try to create sections so the
keys in the sections do not have dots. if maxdepth is given, it will create sections with $maxdepth
members in them (or less if it is not possible). It won't use the special key name
"."
<?php
function prepare_ini($arr, $maxdepth=NULL){
$res = array();
prepare_ini__1($res, $arr, $maxdepth);
return $res;
}
function prepare_ini__1(
&$res, $arr, $maxdepth,
$prefix1="", $prefix2="", $depth=0,
$self='prepare_ini__1')
{
foreach($arr as $key=>$val){
if(is_array($val)){
if(is_null($maxdepth) or $depth < $maxdepth){
$newprefix = $prefix1 ? "$prefix1.$key" : $key;
$self($res, $val, $maxdepth, $newprefix, $prefix2, $depth+1);
}else{
$newprefix = $prefix2 ? "$prefix1.$key" : $key;
$self($res, $val, $maxdepth, $prefix1, $newprefix, $depth+1);
}
}else{
$newprefix = $prefix2 ? "$prefix2.$key" : $key;
if(!isset($res[$prefix1])) $res[$prefix1] = array();
$res[$prefix1][$newprefix] = $val;
}
}
}
// kate: indent-width 4; tab-width 8; space-indent on;
// kate: replace-tabs off; remove-trailing-space on;
?>