Ok so I want to do something similar to how Simple Machine Forum edits some variable within the Admin panel on the forum. For instance I have a settings.php file. I want tool.php to open and find all declared php variables in the settings.php like $background_color='Orange' and output in tools.php Background Color: Orange inside of a form tag that, once changed to 'Purple' and submitted, replaces 'Orange' with 'Purple' and now if i open 'settings.php' the variable inside the file is now "$background_color='Purple'" without having to go in an manually edit it. I can just submit the new data for the variable and replace the old.
3条回答 默认 最新
- doqau82086 2017-07-06 08:33关注
To keep the data persistent, you will need to store data in a database or separate file e.g. JSON file. Then you can use that data everywhere it is needed.
Here is an example using a JSON file.
setting_variables.json:
{ "background": "red", "color": "white" }
settings.php
$settings = json_decode(file_get_contents("settings_variables.json"), true); $background = $settings['background'];
tools.php
include ("settings.php"); // If form is posted if(isset($_POST['submit'])){ /* Updating variables in JSON file*/ //Get settings_json file $setting_vars = json_decode(file_get_contents('settings_variables.json'), true); // Update variable $background = $setting_vars['background'] = $_POST['color']; // Store variable value to JSON file file_put_contents("settings_variables.json", json_encode($setting_vars)); } ?> <form method="post" <?php echo "style='background-color:".$background . "'"; ?>> <select name="color"> <option value="red">red</option> <option value="blue">blue</option> <option value="orange">orange</option> <option value="yellow">yellow</option> <option value="purple">purple</option> </select> <input type="submit" name="submit"/> </form>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 机器学习能否像多层线性模型一样处理嵌套数据
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效