]; then modify the page, the code is [$old_inf = "/define\ ('$key','.*?'\);/";]."/> ]; then modify the page, the code is [$old_inf = "/define\ ('$key','.*?'\);/";].">
search
HomeBackend DevelopmentPHP ProblemHow to modify the configuration file in php?

How to modify the configuration file in php?

Jun 11, 2020 am 10:36 AM
Configuration file

How to modify the configuration file in php?

How to modify the configuration file in php?

How to modify the configuration file in php:

1. Modify the boot page first

<?php
include("dbconfig.php");
?>
<form action="edit.php" method="post">
    <br />
    端口:<input type="text" name="DB_HOST" value="<?php echo DB_HOST;?>" /><br />
    用户名:<input type="text" name="DB_USER" value="<?php echo DB_USER;?>" /><br />
    密码:<input type="text" name="DB_PASS" value="<?php echo DB_PASS;?>" /><br />
    数据库名:<input type="text" name="DB_NAME" value="<?php echo DB_NAME;?>" /><br />
    <input type="submit" value="修改" />
</form>

2. Modify the page

<?php
//获取配置文件的内容
$string = file_get_contents(&#39;config.php&#39;);
foreach ($_POST as $key=>$value) {
    //正则匹配对应的一行
    $old_inf = "/define\(&#39;$key&#39;,&#39;.*?&#39;\);/";
    //要修改成的数据
    $new_inf = "define(&#39;$key&#39;,&#39;$value&#39;);";
    //替换
    $string = preg_replace($old_inf,$new_inf,$string);
}
//写入配置文件
file_put_contents(&#39;config.php&#39;,$string);
echo "修改成功";

Recommended tutorial: "PHP Video Tutorial"

The above is the detailed content of How to modify the configuration file in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.