Share a PHP config class written by respective

Source: Internet
Author: User
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!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.