Parse an INI formatted string and convert it into an object.
{
$sections = (isset($options['processSections'])) ? $options['processSections'] : false;
$hash = md5($data . ':' . (int) $sections);
if (isset(self::$cache[$hash]))
{
return self::$cache[$hash];
}
if (empty($data))
{
return new stdClass;
}
$obj = new stdClass;
$section = false;
$lines = explode("\n", $data);
foreach ($lines as $line)
{
$line = trim($line);
if (empty($line) || ($line{0} == ';'))
{
continue;
}
if ($sections)
{
$length = strlen($line);
if (($line[0] == '[') && ($line[$length - 1] == ']'))
{
$section = substr($line, 1, $length - 2);
$obj->$section = new stdClass;
continue;
}
}
elseif ($line{0} == '[')
{
continue;
}
if (!strpos($line, '='))
{
continue;
}
list ($key, $value) = explode('=', $line, 2);
if (preg_match('/[^A-Z0-9_]/i', $key))
{
continue;
}
$length = strlen($value);
if ($length && ($value[0] == '"') && ($value[$length - 1] == '"'))
{
$value = stripcslashes(substr($value, 1, ($length - 2)));
$value = str_replace('\n', "\n", $value);
}
else
{
if ($value == 'false')
{
$value = false;
}
elseif ($value == 'true')
{
$value = true;
}
elseif (is_numeric($value))
{
if (strpos($value, '.') !== false)
{
$value = (float) $value;
}
else
{
$value = (int) $value;
}
}
}
if ($section)
{
$obj->$section->$key = $value;
}
else
{
$obj->$key = $value;
}
}
self::$cache[$hash] = clone ($obj);
return $obj;
}