There are many configuration file format, pure php, yaml, ini, json or xml. json and xml are easy to parse in PHP, for json, just use json_decode($file);.
I think json is not good readable for human, ini and yaml is better. The different of ini and yaml is nest ability. yaml is easier to nested.
parse ini file
The sample code to parse ini file in PHP:
###### config.ini ######
db_driver=mysql
db_user=root
db_password=root
[dsn]
host=localhost
port=3306
dbname=localhost
<?php
//parse config.ini
$ini = dirname(__FILE__) . "config.ini" ;
$parse = parse_ini_file ( $ini , true ) ;
$driver = $parse [ "db_driver" ] ;
$dsn = "${driver}:" ;
foreach ( $parse [ "dsn" ] as $k => $v ) {
$dsn .= "${k}=${v};" ;
}
parse yaml
what is yaml
YAML is a human friendly data serialization
standard for all programming languages.
parse yaml via php
sitename: saharabear.com
date: "2012-05-01"
contact:
number: 1585410
address: |-
RM 807 No 1000
Shunhua RD
city: Shanghai
business:
development:
price: something
testing:
price: something
<?php
//parse config.yaml
$parsed = yaml_parse_file(dirname(__FILE__).'/config.yml');
var_dump($parsed);
//that's all
At last, do not use Windows as PHP development platform, do not use Windows as Python development platform, do not use Windows as Lua development platform, wasted too much time on working environment.
Slackware or FreeBSD is better.