PHP发布到变量,然后追加到TXT

编程入门 行业动态 更新时间:2024-10-26 20:31:00
本文介绍了PHP发布到变量,然后追加到TXT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了这个问题,无法完成这个简单的脚本.基本上,我想从表单中获取帖子,将其分配给变量,然后将变量附加到预先存在的example.txt文件中.对于缺少示例,我深表歉意.出去吃饭后,我和我的小s子切换到了手机.谁能发表一个简单的例子,然后让我建立这个基础?预先感谢

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>

有关更多信息,请查看 us3.php/file_put_contents .

Check out us3.php/file_put_contents for more information.

更多推荐

PHP发布到变量,然后追加到TXT

本文发布于:2023-10-12 01:13:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   PHP   TXT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!