PHP Classes

File: include/read_ini_file.php

Recommend this page to a friend!
  Classes of hwrProgs   NabiCI   include/read_ini_file.php   Download  
File: include/read_ini_file.php
Role: Auxiliary script
Content type: text/plain
Description: read_ini_file.php
Class: NabiCI
Continuous integration framework
Author: By
Last change:
Date: 14 years ago
Size: 1,617 bytes
 

Contents

Class file image Download
<?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;
}

?>