Ti ringrazio, stavo giustappunto provando... ma ho incontrato un problema che mi ha rovinato i programmi: il file non e' completamente ".ini" compliant (lol) ...intendo dire che ci sono commenti messi dentro con "//" e il parse_ini si inchioda.. e poi ci sono delle variabili all'interno della sezione ripetute (stesso nome) e il parse salva solo l'ultima variabile! Risultato: mi devo leggere riga per riga "a mano".. ho trovato questo codice.. ma non so perche' non funziona!
<?php
function parse_ini_str($Str,$ProcessSections = TRUE) {
$Section = NULL;
$Data = array();
if ($Temp = strtok($Str,"\r\n")) {
do {
switch ($Temp{0}) {
case ';':
case '#':
break;
case '[':
if (!$ProcessSections) {
break;
}
$Pos = strpos($Temp,'[');
$Section = substr($Temp,$Pos+1,strpos($Temp,']',$Pos)-1);
$Data[$Section] = array();
break;
default:
$Pos = strpos($Temp,'=');
if ($Pos === FALSE) {
break;
}
$Value = array();
$Value["NAME"] = trim(substr($Temp,0,$Pos));
$Value["VALUE"] = trim(substr($Temp,$Pos+1),' "');
if ($ProcessSections) {
$Data[$Section][] = $Value;
}
else {
$Data[] = $Value;
}
break;
}
} while ($Temp = strtok("\r\n"));
}
return $Data;
}
$filename = "result.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo call_user_func('parse_ini_str', $contents);
?>