编辑配置文件 [英] Editing Configuration File
本文介绍了编辑配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了一个很小的站点,只有几个配置设置,例如标题,标语等...
并且我正在尝试使系统来编辑将保存到config.php文件中的那些设置.
配置如下:
Hi, i made a small site with few configurations settings such as title, slogan, etc...
and i am trying to make a system to edit those settings which will be saved into config.php file.
Configuration goes as follow:
<?php
$conf['title'] = 'Title';
$conf['slogan'] = 'slogan for company';
?>
我更改设置的代码如下:
My code to change setting goes as follow:
<?php
include ('system/config/config.php');
?>
<form method="post" action="">
<h2>Main Settings</h2>
<p>
<label>Site's Title:</label><br />
<input type="text" name="title" class="text medium error" value="<?php echo $conf['title']; ?????>"/>
</p>
<p>
<label>Site's ip:</label><br />
<input type="text" name="slogan" class="text medium error" value="<?php echo $conf['slogan']; ?????>"/>
</p>
<p>
<input type="submit" class="submit small" name='edit' value="Save" />
</p>
</form>
<?php
$configs = array();
function write($filename, $content = '')
{
if(file_exists($filename))
{
if(is_writable($filename))
{
$fh = fopen($filename, 'w+');
fwrite($fh, $content);
fclose($fh);
return TRUE;
}
}
return FALSE;
}
$content = file_get_contents('system/config/config.php');
if(isset($_POST['edit']))
{
foreach ($_POST as $k => $v)
{
$configs[$k] = $v;
$search = '$conf[\''.$k.'\'] = \''.addslashes($configs[$k]).'\';';
$replace = '$conf[\''.$k.'\'] = \''.addslashes($_POST[$k]).'\';';
$contents = str_replace($search, $replace, $content);
}
write('system/config/config.php', $contents);
echo 'saved the configurations';
}
?>
问题是它没有保存它.我知道它试图写入文件,但配置没有改变.我究竟做错了什么?一旦代码生效,我将对其进行整理.
谢谢.
The problem is its not saving it. I know its trying to write to the file but the config is not changing. What am i doing wrong? I will be organizing the code once its working.
Thanks.
推荐答案
conf [' title' span>] = ' 标题';
conf['title'] = 'Title';
conf [' 标语'] = ' 公司标语'; ?>
conf['slogan'] = 'slogan for company'; ?>
我更改设置的代码如下:
My code to change setting goes as follow:
<?php
include ('system/config/config.php');
?>
<form method="post" action="">
<h2>Main Settings</h2>
<p>
<label>Site's Title:</label><br />
<input type="text" name="title" class="text medium error" value="<?php echo
conf ['title']; ?????> ;" > < /p > < p > < label > 站点的ip: < /label > < br > < 输入 =" 文本" 名称 标语" 类 =" 文本媒体错误" 值 <?php echo
conf['title']; ?????>"/> </p> <p> <label>Site's ip:</label><br /> <input type="text" name="slogan" class="text medium error" value="<?php echo
这篇关于编辑配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文