note 75355 added to function.parse-ini-file
| From: | Mildred at osu1 dot php dot net | Date: | Fri, 25 May 2007 07:42:27 +0000 |
| Subject: | note 75355 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126887@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 read_ini($file)
it adds functionnality to ini files. You can use arbitrary deep structure simlply by putting dots
(.) in names (section names or key names). if a section name is "." (and nothing else than
a dot) it will be as if the keys following were written at the beginning of the file (that is before
any section). If a key name is "." (a single dot) it would be as if the key was written
at the beginning of the file and the name of the key were exactly the name in the section it apears
on. If a name begin or end with a dot, or if there two dots in a name, it will create a node whose
name is the empty string ("")
<?php
function read_ini($file){
$ini = parse_ini_file($file, true);
$res = array();
foreach($ini as $header=>$content){
if($header=='.') $header_parts = array();
else $header_parts = explode('.', $header);
$current = &$res;
foreach($header_parts as $part){
if(ereg('^[0-9]+$', $part)) $part = (int) $part;
if(!isset($current[$part])) $current[$part] = array();
$current =& $current[$part];
}
foreach($content as $key=>$value){
if($key=='.') $key_parts = array();
else $key_parts = explode('.', $key);
$lastpart = array_pop($key_parts);
$current2 = &$current;
foreach($key_parts as $part){
if(ereg('^[0-9]+$', $part)) $part = (int) $part;
if(!isset($current2[$part])){
$current2[$part] = array();
}elseif(!is_array($current2[$part])){
$current2[''] = $current2;
$current2[$part] = array();
}
$current2 =& $current2[$part];
}
$current2[$lastpart] = $value;
}
}
return $res;
}
// 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/75355
Del: integrated -- https://master.php.net/note/delete/75355/integrated
Del: useless -- https://master.php.net/note/delete/75355/useless
Del: bad code -- https://master.php.net/note/delete/75355/bad+code
Del: spam -- https://master.php.net/note/delete/75355/spam
Del: non-english -- https://master.php.net/note/delete/75355/non-english
Del: in docs -- https://master.php.net/note/delete/75355/in+docs
Del: other reasons-- https://master.php.net/note/delete/75355
Reject -- https://master.php.net/note/reject/75355
Search -- https://master.php.net/manage/user-notes.php