zoukankan      html  css  js  c++  java
  • php动态修改配置文件

    <?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>";
  • 相关阅读:
    LeetCode 79. 单词搜索
    LeetCode 1143. 最长公共子序列
    LeetCode 55. 跳跃游戏
    LeetCode 48. 旋转图像
    LeetCode 93. 复原 IP 地址
    LeetCode 456. 132模式
    LeetCode 341. 扁平化嵌套列表迭代器
    LeetCode 73. 矩阵置零
    LeetCode 47. 全排列 II
    LeetCode 46. 全排列
  • 原文地址:https://www.cnblogs.com/lzy007/p/6220490.html
Copyright © 2011-2022 走看看