iugo
V2EX  ›  PHP

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

  •  
  •   iugo · Jan 13, 2015 · 3184 views
    This topic created in 4140 days ago, the information mentioned may be changed or developed.

    我看到一种写法:

    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));
    

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

    3 replies    2015-01-14 15:04:06 +08:00
    vibbow
        1
    vibbow  
       Jan 13, 2015
    config.php:
    <?php //config in json


    $config = file_get_contents('config.php')
    $config = substr($config, 8);
    $config = json_decode($config, true);
    Actrace
        2
    Actrace  
       Jan 14, 2015
    楼主这是用生命在水贴啊,不怕被各路大神骂死嘛....
    iugo
        3
    iugo  
    OP
       Jan 14, 2015
    @Actrace 确为新手. 若是发错地方, 还请见谅... 若叨扰到大神, block 即可.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   926 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 19:42 · PVG 03:42 · LAX 12:42 · JFK 15:42
    ♥ Do have faith in what you're doing.