note 37756 deleted from function.parse-ini-file by victor
| From: | victor@php.net | Date: | Sat, 19 Jun 2004 15:16:41 +0000 |
| Subject: | note 37756 deleted from function.parse-ini-file by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71352@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Here's a function that parses an inifile from a string rather than from a file (fopen wrappers
won't work on parse_ini_file):
<code>
function parse_ini_str($str, $process_sections= FALSE) {
$section= NULL;
$data= array();
if ($t= strtok($str, "\r\n")) do {
switch ($t{0}) {
case ';':
case '#':
break;
case '[':
if (!$process_sections) break;
$p= strpos($t, '[');
$section= substr($t, $p+ 1, strpos($t, ']', $p)- 1);
$data[$section]= array();
break;
default:
if (FALSE === ($p= strpos($t, '='))) break;
$key= trim(substr($t, 0, $p));
$value= trim(substr($t, $p+ 1), ' "');
if ($process_sections) {
$data[$section][$key]= $value;
} else {
$data[$key]= $value;
}
break;
}
} while ($t= strtok("\r\n"));
return $data;
}
</code>