码迷,mamicode.com
首页 > Web开发 > 详细

php动态修改配置文件

时间:2016-12-25 23:30:22      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:读取   nbsp   type   array   .com   elf   contents   数据库   [1]   

 

技术分享

<?php
define("host","localhost");
define("port","3306");
define("user","root");
define("pwd","root2");
define("dbname","text23");

 

<?php
//1.读取配置文件的信息
$info = file_get_contents("dbcongfig.php");
$keyinfo = array("host"=>"主机","port"=>"端口","user"=>"账号","pwd"=>"密码","dbname"=>"数据库",);
//2.使用正则表达式解析配置文件的信息 .任意字符  * 任意数量 ?拒绝贪婪匹配
preg_match_all("/define\(\"(.*?)\",\"(.*?)\"\)/",$info,$temp);

echo "<h1>编辑配置文件</h1>";
echo "<form action=‘upt.php‘ method=‘post‘ >";
foreach($temp[1] as $k=>$v){
    echo "$keyinfo[$v]:<input type=‘text‘ name=‘{$v}‘ value=‘{$temp[2][$k]}‘  /><br/><br/>";
}
echo "<input type=‘submit‘ value=‘修改‘ />&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<input type=‘reset‘ value=‘重置‘ />";
echo "</form>";
<?php
//1.获取配置信息
$info = file_get_contents("dbcongfig.php");
//2.对配置文件进行正则替换
foreach($_POST as $k=>$v){
    $info = preg_replace("/define\(\"{$k}\",\".*?\"\)/","define(\"{$k}\",\"{$v}\")", $info);
}
file_put_contents("dbcongfig.php", $info);
echo "<script>alert(‘修改成功‘);</script>";
echo "<script>self.location=‘file_get_content.php‘</script>";

 

php动态修改配置文件

标签:读取   nbsp   type   array   .com   elf   contents   数据库   [1]   

原文地址:http://www.cnblogs.com/lzy007/p/6220490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!