note 96232 deleted from function.parse-ini-string by danbrown
| From: | danbrown@php.net | Date: | Tue, 16 Feb 2010 15:48:31 +0000 |
| Subject: | note 96232 deleted from function.parse-ini-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166012@lists.php.net to get a copy of this message | ||
Note Submitter: peter dot pshenichny at gmail dot com
----
Thanks for the script below.
Added some additional functionality for rows without any params such us:
[example : something]
if(!function_exists('parse_ini_string')){
function parse_ini_string($str, $ProcessSections=false){
$lines = explode("\n", $str);
$return = array();
$inSect = false;
foreach($lines as $line){
$line = trim($line);
if(!$line || $line[0] == "#" || $line[0] == ";")
continue;
if($line[0] == "[" && $endIdx = strpos($line, "]")){
$inSect = substr($line, 1, $endIdx-1);
if($ProcessSections && !isset($return[$inSect])) $return[$inSect] = array();
continue;
}
if(!strpos($line, '=')) // (We don't use "=== false" because
value 0 is not valid as well)
continue;
$tmp = explode("=", $line, 2);
if($ProcessSections && $inSect)
$return[$inSect][trim($tmp[0])] = trim($tmp[1], " \t\"\'");
else
$return[trim($tmp[0])] = trim($tmp[1], " \t\"\'");;
}
return $return;
}
}