Possible Duplicate:
Reading and Writing Configuration Files
Okay, I have a config file, which contains some information that I would like the user to be able to change. I've already thought about holding the information in a MySQL table but this isn't a good idea as I've got my Database class included AFTER my configuration variables and this would mess up my code structure.
Any idea how to read/write variables/specific lines of a file? Here's my global config file.>error_reporting(E_ALL);
/*
The parameters used site-wide
First set are Datbase parameters
And second set are the salts used to generate strings
*/
$params['db']['host'] = 'localhost';
$params['db']['username'] = 'root';
$params['db']['password'] = 'waffliner';
$params['db']['db_name'] = 'habcms';
$params ['core']['salt1'] = "184962574320355793361124913390";
$params['core']['salt2'] = "13952134426315134482857516025";
$params['core']['timeout'] = "60 minutes";
try {
include_once("core.inc.php");
include_once("db.inc.php");
include_once("user.inc.php");
} catch(exception $e) {
echo $e->getMessag开发者_StackOverflow中文版e();
}
?>
JSON♥ is your friend.
{
"db": {
"host" : "localhost",
"username" : "root"
...
},
...
}
If you want to do so, you need to store you configuration in a non-PHP file.
You can, for example, store your config in an .ini file and read it with parse_ini_file().
精彩评论