Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function parse_ini_file_with_brackets($filename, $use_include_path = false)
- {
- $array = array();
- if($file = @file($filename))
- {
- if($use_include_path)
- {
- foreach($file as $row)
- {
- if(substr(ltrim($row), 0, 1) != ';' && strlen(trim($row)) > 0)
- {
- $sectionopener = substr(ltrim($row), 0, 1);
- if($sectionopener == '[' && $use_include_path)
- {
- $lastsection = substr(trim($row), 1, -1);
- if(count($array[$lastsection]) == 0)
- $array[$lastsection] = array();
- }
- elseif($sectionopener != '[')
- {
- $trimed = trim($row);
- $firstpos = strpos($trimed, '=');
- $name = rtrim(substr($trimed, 0, $firstpos));
- $value = ltrim(substr($trimed, $firstpos + 1));
- $array[$lastsection][$name] = $value;
- }
- }
- }
- }
- else
- {
- foreach($file as $row)
- {
- if(substr(ltrim($row), 0, 1) != ';' && strlen(trim($row)) > 0)
- {
- if(substr(ltrim($row), 0, 1) != '[')
- {
- $trimed = trim($row);
- $firstpos = strpos($trimed, '=');
- $name = rtrim(substr($trimed, 0, $firstpos));
- $value = ltrim(substr($trimed, $firstpos + 1));
- $array[$name] = $value;
- }
- }
- }
- }
- return $array;
- }
- else
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement