如何更新php文件中的變量並將其保存到磁盤?我試圖做一個小的CMS,在一個文件,沒有數據庫,我希望能夠更新配置變量,我做了一個設置頁面,當我更新我想變量更新在php文件中。 下面會更新變量,但當然不會將它保存到php文件中,那麼我該怎麼做?PHP如何更新php文件中的變量
<?php
$USER = "user";
if (isset($_POST["s"])) { $USER = $_POST['USER']; }
?>
<html><body>
Current User: <?php echo $USER; ?>
<form method="post" action="<?php echo $_SERVER["SCRIPT_NAME"]; ?>">
New User<input type="text" name="USER" value="<?php echo $USER; ?>"/>
<input type="submit" class="button" name="s" value="Update" />
</form>
</body></html>
我不知道我是否錯過了明顯的? 我想用這樣的事情的:
$newcms = file_get_contents(index.php)
str_replace(old_value, new_value, $newcms)
file_puts_contents(index.php, $newcms)
但它似乎並不像正確的解決方案......
林困惑,你需要更好地解釋自己你想要做什麼 – JimmyBanks 2012-02-11 23:40:07