Reading config files

From: Date: Thu, 24 Jan 2002 23:23:26 +0000
Subject: Reading config files
Groups: php.general 
Request: Send a blank email to php-general+get-82000@lists.php.net to get a copy of this message
Hiya, Just looking for some tips on reading formatted config files. The config file is pretty strictly formatted.. here's an example: # this is a comment. any text on a line after a # should be ignored section "section1" {
    option "value";
    option-array {
        "value 1";
        1234; # numerical value
        anothervalue; # text without quotes
    };
    option-array-on-one-line { value1; "value 2"; 46; };
}; That's kind of a worst-case scenario. Most sections will only have 1-2 options, and not contain subsections, etc.. but some do contain it, so is why I constructed this. I'm not looking for actual code, exactly.. more or less tips on where to start. Should I come up with a magical regexp that can sift through the data, or some kind of recursive function that reads values and returns arrays with the values.. Values are always terminated by a ; character, unless of course that ; character lies within quotes. Pretty standard stuff, but it's my first attempt at parsing something this complex. Any kind of help on this is appreciated. Mike -- Most burning issues generate far more heat than light.

« previous php.general (#82000) next »