Hi Walter, You may want to look into PEAR's config package. It does pretty much all you have listed here and a lot more. I just started looking into it today. I haven't looked closely at the code so I don't know how efficiently it handles everything it does but it may give you some ideas. As far as I tell it can handle Generic Config files, .ini files, XML config files and more.
http://pear.php.net/package/Config http://pear.php.net/manual/en/package.configuration.php ck -- Cheap Domain Registration | Web Hosting | Email Packages | + more Fantastic prices -- Even better service. http://www.hosttohost.net jsWalter [EMAIL PROTECTED] on 10/22/03 1:10 AM wrote: > I need to read (write comes later) from a config file that we used to handle > manually. > > I'm getting lazy, so I'm writing a web interface for this. > > What I have does this... > - open a given file > - dump entire file into a string > - explode string into an array at the EOL marker > - walk down this new array > - decide if there is anything in current element > - decide if current line is a comment > - split line at '=' into 2 variables > - add new key and value from these variables back into array > - kill original array element > > There must be a better way to do this. > > All this seems a bit over kill to me. > > Does anyone have any ideas on this? > > Thanks > > Walter > > This is what I have... > > <?php > > $config = $list . '/home/walter/vmd/config'; > > // Open the file > $handle = fopen ($config, "r"); > > // Read entire file into var > $content = fread($handle, filesize($config)); > > // convert var into array and explode file via line break > $content = split("\r\n", $content); > > // close file > fclose($handle); > > // Loop through file contents array > foreach ($content as $i => $value) > { > // If we have any data in this line > if (! empty ($value)) > { > // If this line is not a comment > if ( $value{0} != '#') > { > list($a, $b) = split("=", $value); > $content[$a] = $b; > } > > // kill original array element > unset($content[$i]); > } > } > > // show me what I have > echo '<pre>'; > echo print_r($content); > echo '</pre>'; > > ?> > > # Sample config file data, just 2 lines from the file... > # > # The "Personal Name" of the list, used in outgoing headers. > # If empty, default is the same as the list's username. > # if explicitly `false', then it is redefined empty. > LIST_NAME="RMT Working Group" > > # The address of the list's admin or owner. > # if explicitly `false', then it is redefined empty. > [EMAIL PROTECTED] > > ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php