note 75356 added to function.parse-ini-file
| From: | Mildred at osu1 dot php dot net | Date: | Fri, 25 May 2007 07:42:35 +0000 |
| Subject: | note 75356 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126888@lists.php.net to get a copy of this message | ||
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;
?>
----
Server IP: 195.221.21.36
Probable Submitter: 194.206.50.185
----
Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php
Edit -- https://master.php.net/note/edit/75356
Del: integrated -- https://master.php.net/note/delete/75356/integrated
Del: useless -- https://master.php.net/note/delete/75356/useless
Del: bad code -- https://master.php.net/note/delete/75356/bad+code
Del: spam -- https://master.php.net/note/delete/75356/spam
Del: non-english -- https://master.php.net/note/delete/75356/non-english
Del: in docs -- https://master.php.net/note/delete/75356/in+docs
Del: other reasons-- https://master.php.net/note/delete/75356
Reject -- https://master.php.net/note/reject/75356
Search -- https://master.php.net/manage/user-notes.php