The example in this article describes the simple method of PHP generating txt files to the specified directory. Share it with everyone for your reference, the details are as follows:
<?php //fopen第二个参数可以是以下四个,区别就是是清空内容再写还是在后面累加内容 //"w" 写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 //"w+" 读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 //"a" 写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。 //"a+" 读写方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。 $myfile = fopen("c:/newfile.txt", "a") or die("Unable to open file!");//这个是在c盘根目录生成文件 $txt = $_GET;//获取参数 $b=""; foreach($txt as $k=>$v){ $b = $b ."[".$k."]=>".$v."\n"; } $txt1 = $_POST; foreach($txt1 as $k=>$v){ $b = $b ."[".$k."]=>".$v."\n"; } $b = $b."123"; fwrite($myfile, $b);//写入内容,可以写多次哦,不过没啥意义,因为你拼接好字符串,一次写入就行了 fclose($myfile);//关闭该操作 ?>
Easy and easy to use method is
file_put_contents("c:/zll.txt","内容");
Readers who are interested in more PHP related content can check out the special topics of this site: "Summary of PHP File Operations", "Summary of PHP Operations and Operator Usage", "Summary of PHP Network Programming Skills", "Introduction Tutorial on PHP Basic Grammar" ", "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "Introduction to PHP object-oriented programming tutorial", "Summary of PHP string (string) usage" , "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone in PHP programming.