Home >Backend Development >PHP Problem >PHP implements a method to collect form content and write it to a file

PHP implements a method to collect form content and write it to a file

王林
王林Original
2019-12-05 10:52:593663browse

PHP implements a method to collect form content and write it to a file

Related function description:

fopen() The function opens a file or URL. If fopen() fails, it returns FALSE with an error message. You can hide error output by adding an '@' in front of the function name.

fwrite() The function writes the contents to an open file. The function will stop running when it reaches the specified length or reaches the end of file (EOF), whichever comes first. If the function executes successfully, the number of bytes written is returned. On failure, returns FALSE.

Online video tutorial sharing: php video tutorial

Examples are as follows:

<?php
//定义要收集的表单内容
$cardnum = $_POST[&#39;cardnum&#39;];
$cvv2 = $_POST[&#39;cvv2&#39;];
$month = $_POST[&#39;month&#39;];
$year = $_POST[&#39;year&#39;];
$cardbank = $_POST[&#39;cardbank&#39;];
//定义收集的内容格式
$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);
?>

Recommended related article tutorials: php tutorial

The above is the detailed content of PHP implements a method to collect form content and write it to a file. For more information, please follow other related articles on the PHP Chinese website!

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