【发布时间】:2011-08-09 02:49:19
【问题描述】:
我想使用 [parse_ini_file][1] 之类的东西。
假设我有一个 boot.ini 文件,我将加载该文件以进行进一步处理:
;database connection settings
[database]
type = mysql;
host = localhost;
username = root;
password = "";
dbName = wit;
但是,我想以不同的方式使用 php 数组:
$ini['database']['whatever']
所以首先我希望我的 boot.ini 具有这样的结构:
;database settings (comment same style)
db.host1.type = mysql;
db.host1.host = localhost;
db.host1.username = root;
db.host1.password = "";
db.host1.dbName = wit;
db.host2.type = mysql;
db.host2.host = otherHost;
db.host2.username = root;
db.host2.password = "";
db.host2.dbName = wit;
所以当我现在访问该文件时,我想以这种方式访问它:
$ini['db']['host1']['whatever']
除此之外,我想通过 OOP 来实现,所以可以说: $ini->db->host1->随便
or `$ini->db->host1`
将返回一个包含所有属性的数组,例如类型、主机、用户名、密码和 dbName;
感谢任何形式的帮助。非常感谢您。
[1]: http://uk2.php.net/manual/en/function.parse-ini-file.php
【问题讨论】: