Advertisement
Guest User

redplug

a guest
Jul 22nd, 2009
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1.     function parse_ini_file_with_brackets($filename, $use_include_path = false)
  2.     {
  3.         $array = array();
  4.         if($file = @file($filename))
  5.         {
  6.             if($use_include_path)
  7.             {
  8.                 foreach($file as $row)
  9.                 {
  10.                     if(substr(ltrim($row), 0, 1) != ';' && strlen(trim($row)) > 0)
  11.                     {
  12.                         $sectionopener = substr(ltrim($row), 0, 1);
  13.                         if($sectionopener == '[' && $use_include_path)
  14.                         {
  15.                             $lastsection = substr(trim($row), 1, -1);
  16.                             if(count($array[$lastsection]) == 0)
  17.                                 $array[$lastsection] = array();
  18.                         }
  19.                         elseif($sectionopener != '[')
  20.                         {
  21.                             $trimed = trim($row);
  22.                             $firstpos = strpos($trimed, '=');
  23.                             $name = rtrim(substr($trimed, 0, $firstpos));
  24.                             $value = ltrim(substr($trimed, $firstpos + 1));
  25.                             $array[$lastsection][$name] = $value;
  26.                         }
  27.                     }
  28.                 }
  29.             }
  30.             else
  31.             {
  32.                 foreach($file as $row)
  33.                 {
  34.                     if(substr(ltrim($row), 0, 1) != ';' && strlen(trim($row)) > 0)
  35.                     {
  36.                         if(substr(ltrim($row), 0, 1) != '[')
  37.                         {
  38.                             $trimed = trim($row);
  39.                             $firstpos = strpos($trimed, '=');
  40.                             $name = rtrim(substr($trimed, 0, $firstpos));
  41.                             $value = ltrim(substr($trimed, $firstpos + 1));
  42.                             $array[$name] = $value;
  43.                         }
  44.                     }
  45.                 }
  46.             }
  47.             return $array;
  48.  
  49.         }
  50.         else
  51.             return FALSE;
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement