PHP simply implements a method to generate txt files to a specified directory, _PHP tutorial

WBOY
Release: 2016-07-12 08:53:25
Original
862 people have browsed it

PHP simply implements the method of generating txt files to the specified directory.

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:

<&#63;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);//关闭该操作
&#63;>

Copy after login

Easy and easy to use method is

file_put_contents("c:/zll.txt","内容");

Copy after login

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1123843.htmlTechArticlePHP simply implements the method of generating txt files to the specified directory. This article describes the simple implementation of PHP to generate txt files to the specified directory. directory method. Share it with everyone for your reference, the details are as follows:...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template