note 43234 added to function.parse-ini-file
| From: | forceoneatjustduck dot net at rn2 dot php dot net | Date: | Tue, 15 Jun 2004 00:00:50 +0000 |
| Subject: | note 43234 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-71071@lists.php.net to get a copy of this message | ||
A better version of parse_ini_str that takes into account values that are named the same.
<?php
function parse_ini_str($Str,$ProcessSections = TRUE) {
$Section = NULL;
$Data = array();
if ($Temp = strtok($Str,"\r\n")) {
do {
switch ($Temp{0}) {
case ';':
case '#':
break;
case '[':
if (!$ProcessSections) {
break;
}
$Pos = strpos($Temp,'[');
$Section = substr($Temp,$Pos+1,strpos($Temp,']',$Pos)-1);
$Data[$Section] = array();
break;
default:
$Pos = strpos($Temp,'=');
if ($Pos === FALSE) {
break;
}
$Value = array();
$Value["NAME"] = trim(substr($Temp,0,$Pos));
$Value["VALUE"] = trim(substr($Temp,$Pos+1),' "');
if ($ProcessSections) {
$Data[$Section][] = $Value;
}
else {
$Data[] = $Value;
}
break;
}
} while ($Temp = strtok("\r\n"));
}
return $Data;
}
?>
Example:
[Files]
File=File1
File=File2
would return:
array (
'Files' => array (
0 => array (
'NAME' => 'File',
'VALUE' => File1',
),
1 => array (
'NAME' => 'File',
'VALUE' => 'File2',
),
),
)
----
Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43234
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43234&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43234&report=yes
Search -- http://master.php.net/manage/user-notes.php