这很容易.只需像其他人提到的那样用php扩展名编写文件.
但我宁愿为配置数据编写一个ini文件,稍后用parse_ini_file加载它们.
更新:这是一个例子:
$config = array(
"database" => "test",
"user" => "testUser"
);
function writeConfig( $filename, $config ) {
$fh = fopen($filename, "w");
if (!is_resource($fh)) {
return false;
}
foreach ($config as $key => $value) {
fwrite($fh, sprintf("%s = %s\n", $key, $value));
}
fclose($fh);
return true;
}
function readConfig( $filename ) {
return parse_ini_file($filename, false, INI_SCANNER_NORMAL);
}
var_dump(writeConfig("test.ini", $config));
var_dump(readConfig("test.ini"));