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

有些常用的配置变量写入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);
此条目发表在 Discuz!, PHP 分类目录,贴了 , 标签。将固定链接加入收藏夹。

php配置变量写入配置文件的方法》有 3 条评论

  1. iseeyou 说:

    学习了,php我也在学

  2. 阿里 说:

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

发表评论

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

*

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