php配置变量写入配置文件的方法

添加评论 2009年10月30日

有些常用的配置变量写入MYSQL比较麻烦,可以写入一个php配置文件,在需要的地方引入这个配置文件即可。写入方法如下(摘入):

$configfile = @file_get_contents('./config.inc.php');
			$configfile = trim($configfile);
			$configfile = preg_replace("/[$]dbhost\s*\=\s*[\"'].*?[\"'];/is", "\$dbhost = '$dbhost';", $configfile);
			$configfile = preg_replace("/[$]dbuser\s*\=\s*[\"'].*?[\"'];/is", "\$dbuser = '$dbuser';", $configfile);
			$configfile = preg_replace("/[$]dbpw\s*\=\s*[\"'].*?[\"'];/is", "\$dbpw = '$dbpw';", $configfile);
			$configfile = preg_replace("/[$]dbname\s*\=\s*[\"'].*?[\"'];/is", "\$dbname = '$dbname';", $configfile);
			$configfile = preg_replace("/[$]adminemail\s*\=\s*[\"'].*?[\"'];/is", "\$adminemail = '$adminemail';", $configfile);
			$configfile = preg_replace("/[$]tablepre\s*\=\s*[\"'].*?[\"'];/is", "\$tablepre = '$tablepre';", $configfile);
			$configfile = preg_replace("/[$]cookiepre\s*\=\s*[\"'].*?[\"'];/is", "\$cookiepre = '".random(3)."_';", $configfile);
 
			@file_put_contents('./config.inc.php', $configfile);
  1. 2009年11月4日 at 02:07 | #1

    学习了,php我也在学

  2. 2009年11月4日 at 17:38 | #2

    学习,学习~

  3. 2009年11月14日 at 09:57 | #3

    简单的变量还行,复杂点的好似建议写入SQL

  1. 还没有 trackbacks
订阅评论