简体   繁体   English

如何使用php将数据从HTML表单导出到csv文件

[英]How can I export data from a HTML form to csv file using php

I have a HTML form constructed by a couple of drop down select fields. 我有一个HTML表单,它由几个下拉选择字段构成。 The submit button generates a string. 提交按钮生成一个字符串。

I need help exporting each string generated to a CSV file. 我需要将生成的每个字符串导出到CSV文件的帮助。 My first thoughts are to take the string from the field and place it in a HTML table, then use a script for exporting it to a file. 我首先想到的是从字段中获取字符串并将其放置在HTML表中,然后使用脚本将其导出到文件中。

I'd appreciate it if you can provide a working example. 如果您能提供一个可行的例子,我将不胜感激。

I am very green in this, so please write slowly. 我对此非常绿色,所以请慢慢写。

Thanks. 谢谢。

A CSV file is simply a comma seperated vector. CSV文件只是逗号分隔的向量。

So each string can be written to a file so that they are separated by commas if you want them in separate columns, or by carriage returns if you want them on separate lines. 因此,可以将每个字符串写入文件,以便如果要在单独的列中将它们用逗号隔开,或者如果要在单独的行中将它们用回车符隔开。

The csv export didn't work, so i am trying to print the text input (that i am generating) to a text area, one by one and it works fine. csv导出无法正常工作,因此我试图将输入的文本(我正在生成)打印到一个文本区域,并一一打印,效果很好。

The problem now is that i want to place a "br" after each link i move to the text area. 现在的问题是,我想在每个链接移至文本区域后放置一个“ br”。 any ideas? 有任何想法吗? here is my code: 这是我的代码:

<input name="result" size="70" class="result" type="text" ></input>
<input type="button" value="Add The Link" onClick="addtext();"></p>
<textarea style="width:509px;" name="outputtext"></textarea><br><br>
<input value="Clear" type="reset">

and in the head are is: 头是:

<script language="javascript" type="text/javascript">
function addtext() {
    var newtext = document.cwm1.result.value;
    document.cwm1.outputtext.value += newtext;
}
</script>

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM