<?php
 
 
/**
 
 * function read_ini_file ($filename, $commentchar=";") is used to read a configuration file
 
 * and returns the settings in it in an Array. 
 
 * 
 
 * @param String $filename
 
 * the configuration file which should be read
 
 * @param String $commentchar
 
 * the char which is used to comment in a configuration file. The comment lines should not be return
 
 * @return Array
 
 * the settings in a configuration file
 
 */
 
 
function read_ini_file ($filename, $commentchar=";") {
 
  $array1 = file($filename);
 
  $array2 = array();
 
  $section = '';
 
  foreach ($array1 as $filedata) {
 
    $dataline = trim($filedata);
 
    $firstchar = substr($dataline, 0, 1);
 
    if ($firstchar!=$commentchar && $dataline!='') {
 
      //It's an entry (not a comment and not a blank line)
 
      if ($firstchar == '[' && substr($dataline, -1, 1) == ']') {
 
        //It's a section
 
        $section = strtolower(substr($dataline, 1, -1));
 
      }else{
 
        //It's a key...
 
        $delimiter = strpos($dataline, '=');
 
        if ($delimiter > 0) {
 
          //...with a value
 
          $key = strtolower(trim(substr($dataline, 0, $delimiter)));
 
          $value = trim(substr($dataline, $delimiter + 1));
 
          if (substr($value, 1, 1) == '"' && substr($value, -1, 1) == '"') { $value = substr($value, 1, -1); }
 
          $array2[$section][$key] = stripcslashes($value);
 
        }else{
 
          //...without a value
 
          $array2[$section][strtolower(trim($dataline))]='';
 
        }
 
      }
 
    }else{
 
      //It's a comment or blank line.  Ignore.
 
    }
 
  }
 
  return $array2;
 
}
 
 
?>
 
 |