PHP 如何写配置文件才好看?

2015-01-13 15:25:09 +08:00
 iugo

我看到一种写法:

class ET {

public static $config = array();

public static function writeConfig($values)
{

if (file_exists($file = PATH_CONFIG."/config.php")) include $file;

if (!isset($config) or !is_array($config)) $config = array();
$config = array_merge($config, $values);
self::$config = array_merge(self::$config, $values);

$contents = "<?php\n";
foreach ($config as $k => $v) $contents .= '$config["'.$k.'"] = '.var_export($v, true).";\n";
$contents .= "\n// Last updated by: ".ET::$session->user["username"]." (".ET::$session->ip.") @ ".date("r")."\n?>";
file_put_contents($file, $contents);
}

}

ET::writeConfig(array("esoTalk.skin" => $skin));

想知道有什么好的轮子可用吗?

2783 次点击
所在节点    PHP
3 条回复
vibbow
2015-01-13 18:39:37 +08:00
config.php:
<?php //config in json


$config = file_get_contents('config.php')
$config = substr($config, 8);
$config = json_decode($config, true);
Actrace
2015-01-14 10:57:46 +08:00
楼主这是用生命在水贴啊,不怕被各路大神骂死嘛....
iugo
2015-01-14 15:04:06 +08:00
@Actrace 确为新手. 若是发错地方, 还请见谅... 若叨扰到大神, block 即可.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/161748

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX