<?php class SimpleINIElement { protected $DataArray, $Mode, $Content, $TempVar, $CurrentData; public function __construct($_FILE='') { { $this->Mode = 'Edit'; $this->ReadFromFile(); } else $this->Mode = 'Create'; } protected function ReadFromFile() { foreach ($this->Content as $line_number => $line) { // category { // gets an array $this->TempVar['section']['line'] = $line_number; // set temporary $this->CurrentData['section'] = $this->TempVar['section']['pattern'][1][0]; // sets a current category for new variables } elseif(preg_match('#.*([A-z0-9]+).*=.*([A-z0-9]+)*#', $line, $data)) { // add new variables (comments and variables) { } else { $var_key = $_value[0]; } } } } public function DocumentWrite($_STATUS='') { if($_STATUS == 'XML') return $this->WriteToXML(); elseif($_STATUS == 'INI') return $this->WriteToINI(); else return $this->DataArray; } public function ThrowSection($_NAME='', $_COMMENT='') { { if($_COMMENT) $_COMMENT = 'y'; else $_COMMENT = 'n'; } else throw new Exception('SimpleINIElement::ThrowVariable error: Category already exists or is argument is
empty.'); } public function ThrowVariable($_NAME='', $_VALUE='', $_CAT='', $_COMMENT='') { if(!$_NAME) throw new Exception('SimpleINIElement::ThrowVariable error: The first param. is empty, its a variable
name!'); if(!$_VALUE) throw new Exception('SimpleINIElement::ThrowVariable error: The 2nd param. is empty, its a variable v
alue!'); if(!$_CAT) throw new Exception('SimpleINIElement::ThrowVariable error: The 3rd param. is empty, its a variable c
ategory!'); throw new Exception('SimpleINIElement::ThrowVariable error: Variable category does not exists.'); if($_COMMENT == '') $_temp_type = 'variable'; else $_temp_type = 'comment'; } protected function WriteToXML() { $xml = '<?xml version="1.0"?>'; foreach ($this->DataArray as $key => $value) { $xml .= '<' .$key. '>'; { foreach ($value['vars'] as $kkey => $vvalue) { $xml .= '<variable name="' .$kkey. '" value="' .$vvalue['value']. '" type="' .$vvalue['type']. '"/>'; } } $xml .= '</' .$key. '>'; } return $xml; } protected function WriteToINI() { $output = ''; foreach ($this->DataArray as $key => $value) { $output .= "[".$key."]\n"; { foreach ($value['vars'] as $kkey => $vvalue) { if($vvalue['type'] == 'comment') $output .= ';'; $output .= $kkey." = ".$vvalue['value']."\n"; } } return $output; } } } $ini = new SimpleINIElement(); $ini->ThrowSection('section1'); $ini->ThrowSection('section2'); $ini->ThrowSection('section3'); $ini->ThrowSection('section4'); $ini->ThrowVariable('TestVariable', 'Test variable value :)', 'section1', true); $ini->ThrowVariable('TestVariable', 'Test variable value :)', 'section2', true); ?>
Problem tkwi w funkcji WriteToINI() gdyż zapisuje ona tylko jedną kategorię zmiennych, a funkcja WriteToXML() zwraca poprawny wynik w XML...
Nie wiem co jest przyczyną... może to mały błąd, literówka?

Dziękuję, Babcia@Stefa