php post 到变量,然后附加到 txt [英] php post to variable and then append to txt
问题描述
我遇到了这个问题,我无法完成这个简单的脚本.基本上,我想从表单中获取一个帖子,将其分配给一个变量,然后将该变量附加到预先存在的 example.txt 文件中.我为缺乏例子道歉,我在和我的姻亲出去吃饭后切换到我的手机.任何人都可以发布一个简单的示例并允许我建立该基础吗?提前致谢
I'm having this problem where I can't manage to accomplish this simple script. Basically, I want to take a post from a form, assign it to a variable, and then append the variable to a preexisting example.txt file. I apologize for the lack of examples, I switched to my phone after I went out to dinner with my inlaws. Could anyone post a simple example andd allow me to build off of that foundation? thanks in advance
推荐答案
以下内容将为您提供一个开始的基础.
The following should give you a foundation to start.
<?php
// Check to see if the form was submitted
if(isset($_POST['action']) && $_POST['action'] == 'add'){
$file = 'example.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= $_POST['test'];
// Write the contents back to the file
file_put_contents($file, $current);
}
?>
<form method="POST">
<!-- This becomes PHP variable $_POST['test'] -->
<input type="text" name="test" />
<input type="hidden" name="action" value="add" />
<input type="submit" value="Add"/>
</form>
查看 http://us3.php.net/file_put_contents 了解更多信息.
Check out http://us3.php.net/file_put_contents for more information.
这篇关于php post 到变量,然后附加到 txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!