Marius Cramer
2013-11-14 b1a6a5a3991cec5cd08873b01376e45d0b247f18
server/lib/classes/ini_parser.inc.php
@@ -1,7 +1,7 @@
<?php
/*
Copyright (c) 2006, Till Brehm, projektfarm Gmbh
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
@@ -28,18 +28,17 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class ini_parser {
class ini_parser{
   var $config;
   function parse_ini_string($ini) {
      $ini = str_replace("\r\n","\n",$ini);
      $lines = explode("\n",$ini);
      $ini = str_replace("\r\n", "\n", $ini);
      $lines = explode("\n", $ini);
      foreach($lines as $line) {
         $line = trim($line);
         if($line != '') {
            $line = trim($line);
            if(preg_match("/^\[([\w\d_]+)\]$/", $line, $matches)) {
               $section = strtolower($matches[1]);
            } elseif(preg_match("/^([\w\d_]+)=(.*)$/", $line, $matches) && $section != null) {
@@ -58,7 +57,11 @@
      foreach($this->config as $section => $data) {
         $content .= "[$section]\n";
         foreach($data as $item => $value) {
            if($value != '') $content .= "$item=$value\n";
            if($value != '') {
               $value  = trim($value);
               $item  = trim($item);
               $content .= "$item=$value\n";
            }
         }
      }
      return $content;
@@ -66,4 +69,4 @@
}
?>
?>