J

parse_ini_file() does exactly what the manual says reads your ini file into an array
(as an aside here php arrays are not arrays but key value pairs)

>From the PHP Help

[first_section]

five = 5
animal = BIRD

[second_section]
path = "/usr/local/bin"
URL = "" class="moz-txt-link-rfc2396E" href="http://www.example.com/~username">"http://www.example.com/~username"

Example 2. parse_ini_file() example

<?php

define
('BIRD''Dodo bird');

// Parse without sections
$ini_array parse_ini_file("sample.ini");
print_r($ini_array);

// Parse with sections
$ini_array parse_ini_file("sample.ini"true);
print_r($ini_array);

?>

Would produce:

Array
(
    [one] => 1
    [five] => 5
    [animal] => Dodo bird
    [path] => /usr/local/bin
    [URL] => http://www.example.com/~username
)
Array
(
    [first_section] => Array
        (
            [one] => 1
            [five] => 5
            [animal] = Dodo bird
        )

    [second_section] => Array
        (
            [path] => /usr/local/bin
            [URL] => http://www.example.com/~username
        )

)


to "recompose" the ini (and write it out) after you have modded the Array would be
quite simple (though there appears to be no corresponding write_ini_file function) it would be something like
(assuming a 'sectioned' INI)

$S = '';
foreach  ($INIArray AS $Section => $Data) {
  $S .= "[$Section ]$CRLF";
  foreach ($Data AS $Key => Value) {
    $S .= "$Key=$Value$CRLF";
  } 
}
fopen();
fwrite($S);

I'm sure you can fill in the gaps

HTH
N




Hi all. I am trying to potentually solve a problem using PHP.
I need to edit a .conf file which is in the format of an INI File.
 
I see PHP has this "parse_ini_file()" but the docs are a bit unclear about certains things like writing back to the file.
 
I have seen some examples, but they are only for what seems like single section ini files, where as the one I want to alter have different section names but the value names are all the same.
 
in Delphi I would go "WriteString('MySection','MyVal','Value')"
 
If there is anyone with PHP knowledge who can help, it woudl be appreciated.
The other idea I have is to use Lazarus to write a small CGI app to do it for me.
 
Jeremy

--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.0.0/751 - Release Date: 07/04/2007 22:57


_______________________________________________ NZ Borland Developers Group Offtopic mailing list Post: Offtopic@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/offtopic Unsubscribe: send an email to [EMAIL PROTECTED] with Subject: unsubscribe

_______________________________________________
NZ Borland Developers Group Offtopic mailing list
Post: Offtopic@delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/offtopic
Unsubscribe: send an email to [EMAIL PROTECTED] with Subject: unsubscribe

Reply via email to