Share a PHP config class that you write yourself
The most important feature of this class is the ability to load the wireless depth of the configuration items, and in the configuration of the use of some configuration items can be modified, the depth of not more than 5 levels.
/** * config.php * * discription * * @filename config.php * @version v1.0 * @update 2011-8-9 * @author Randy.hong * @ Contact [email protected] * @package config */define (' DS ', directory_separator);d efine (' Path_config ', '. '). DS. ' configs ');//config param key Separatordefine (' Config_separator ', '. '); Class config{protected Static $_configarray = Array ();/** * Gets a configuration * @param string $key * @return mixed */public static fu Nction Get ($key = ') {//inlegal Param,return falseif (! $key) {return false;} Without separator in Param, return the whole config Fileif (strpos ($key, Config_separator) ===false) {if (!isset (self::$_ configarray[$key]) {$cfg _file = path_config. DS. ' Config. '. $key. " PHP '; if (file_exists ($cfg _file)) {self::$_configarray[$key] = include_once ($cfg _file);}} return self::$_configarray[$key];} else {$param = explode (Config_separator, $key), if (!isset (self::$_configarray[$param [0]])) {$cfg _file = path_config. DS. ' Config. '. $param [0]. PHP '; if (file_exists ($cfg _file)) {self::$_configarray[$param [0]] = include_once ($cfg _file);}} $tmp _config = null;for ($i =1; $i
Configuration file: configs/config.test.php
Return Array (' test1 ' = = Array (' test2 ' = = Array (' test3 ' = = Array (' test4 ' = = = ' = ' = ' 5555, '),),));
Call file
Include_once (' config.php '); $config = Config::get (' test.test1 ');p rint_r ($config); Config::set (' Test.test1 ', 222); $config = Config::get (' test.test1 ');p rint_r ($config);
1/F lifei6671 2011-08-13
This seems to have the same effect as the Discuz configuration file!