在php中怎样修改配置文件?-PHP问题

资源魔 29 0

正在php中怎么修正设置装备摆设文件?

正在php中修正设置装备摆设文件的办法:

1、先修正疏导页

<?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>

二,修正页面

<?php
//猎取设置装备摆设文件的内容
$string = file_get_contents('config.php');
foreach ($_POST as $key=>$value) {
    //正则婚配对应的一行
    $old_inf = "/define\('$key','.*?'\);/";
    //要修正成的数据
    $new_inf = "define('$key','$value');";
    //交换
    $string = preg_replace($old_inf,$new_inf,$string);
}
//写入设置装备摆设文件
file_put_contents('config.php',$string);
echo "修正胜利";

保举教程:《PHP视频教程》

以上就是正在php中怎么修正设置装备摆设文件?的具体内容,更多请存眷资源魔其它相干文章!

标签: 配置文件 php教程 php故障解决 php使用问题

抱歉,评论功能暂时关闭!