I need a good config file format. I plan on putting to table schema. Like symfony, ruby on rails, etc. What is the best file format for configuration file ? Yaml or XML or JSON encoded file ? Which is the best for this purpose ?
Simple configuration languages, such as JSON, work for many applications, but when you need proper validation, schema, and namespace support, XML is often best.
The most common and standardized formats are YAML, JSON, TOML and INI. A good configuration file should meet at least these 3 criteria: Easy to read and edit: It should be text-based and structured in such a way that is easy to understand. Even non-developers should be able to read.
YAML is a digestible data serialization language often used to create configuration files with any programming language. Designed for human interaction, YAML is a strict superset of JSON, another data serialization language. But because it's a strict superset, it can do everything that JSON can and more.
*.ini
should be pretty good for that
[MyApp]
var1 = "foo"
var2 = "bar"
[MyPlugin]
var1 = "qwe"
You can easily read it using parse_ini_file()
$config = parse_ini_file('/path/to/config/file', true);
echo $config['MyApp']['var2'];
As others have stated, you have loads of options. Just don't invent (i.e. write parsers) such a thing yourself unless you have a really, really good reason to do so (can't think of any). Just evaluate your options:
For example, PHP provides very easy serialize() and unserialize() functions. The format, however, is not as easily readable / editable by humans (XML can also be hard to read, but not as hard as the PHP format. Python's pickle module is even worse.). If you ever need to access data with other languages, this is a bad choice. And think about others - I recently hat to parse PHP serialized data from the Horde project in a python project of mine! JSON is a much better choice because its human-readable (if its "pretty-printed", not in the compacted form!), human-editable and every major language has JSON-support nowadays. However, you will lose backwards compatibility, e.g. with python, JSON requires version 2.6+.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With