gpt4 book ai didi

php - 从表单获取用户输入,使用 php 写入文本文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:58:41 27 4
gpt4 key购买 nike

作为订户获取的一部分,我希望从 html 表单中获取用户输入的数据,并使用 php 将其写入制表符分隔的文本文件。写入的数据需要用制表符分隔并附加在其他数据下方。

单击表单上的订阅后,我希望它删除表单并在 div 中显示一条小消息,如“感谢订阅”。

这将出现在 wordpress 博客上并包含在弹出窗口中。

下面是具体的细节。非常感谢任何帮助。

变量/输入是

$Fname = $_POST["Fname"];
$email = $_POST["emailPopin"];
$leader = $_POST["radiobuttonTeamLeader"];
$industry = $_POST["industry"];
$country = $_POST["country"];
$zip = $_POST["zip"];

$leader 是一个有两个选项的单选按钮,值是"is"和“否”。

$country 是一个包含 40 个左右国家的下拉列表。

所有其他值都是文本输入。

我已经完成并准备好所有基本表单代码,除了操作,我真正需要知道如何做的是:

如何使用 php 写入制表符分隔的文本文件并在提交后用感谢消息交换表单?

再次感谢所有的帮助。

最佳答案

// the name of the file you're writing to
$myFile = "data.txt";

// opens the file for appending (file must already exist)
$fh = fopen($myFile, 'a');

// Makes a CSV list of your post data
$comma_delmited_list = implode(",", $_POST) . "\n";

// Write to the file
fwrite($fh, $comma_delmited_list);

// You're done
fclose($fh);

将制表符中的 , 替换为\t

关于php - 从表单获取用户输入,使用 php 写入文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2009631/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com