诺亚方舟

沉淀

PHP利用数组将配置信息存储在文件中

搭建系统的时候很经常需要依靠一些配置信息来实例化,这些信息一般可存储在数据库或者配置文件中。存储数据库的方式就不说了,下面的这个方法是可利用来存储于文件中,用时直接将文件include进来就可以了。

 

1
2
3
4
5
6
7
8
9
10
11
12
13
static function saveVipThresholdConf($confs){
	global $_sysInfo; 
	$conf_file = dirname(dirname(__FILE__))."/config/".$_sysInfo['plat']."/".OS."/VipThresholdConf.php"; 
	if(!file_exists($conf_file)){ 
		//创建配置文件 
		$fp = @fopen($conf_file, "x"); 
		$re = @fwrite($fp, sprintf("<!--?php return %s ?-->", var_export($confs,true))); 
		fclose($fp); 
	}else{ 
		$re = file_put_contents($conf_file, sprintf("<!--?php return %s ?-->",var_export($confs,true))); 
	} 
		return $re; 
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>