Home >Backend Development >PHP Tutorial >PHP simply implements the method of generating txt files to the specified directory. The method of calling the parent class in PHP. The method of calling the class in PHP. The area of ​​PHP functions and methods.

PHP simply implements the method of generating txt files to the specified directory. The method of calling the parent class in PHP. The method of calling the class in PHP. The area of ​​PHP functions and methods.

WBOY
WBOYOriginal
2016-07-29 08:51:47977browse

The example in this article describes how to simply implement PHP to generate a txt file to a 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);//关闭该操作
?>

The simple method and very easy to use is

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

Readers who are interested in more PHP-related content can check out the special topic of this site: "Summary of PHP File Operations" , "Summary of PHP operations and operator usage", "Summary of PHP network programming skills", "Introduction to PHP basic syntax tutorial", "Summary of PHP operating office document skills (including word, excel, access, ppt)", "php date and Time Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php+mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will explain It will be helpful to everyone in PHP programming.

The above introduces the simple method of generating txt files to a specified directory in PHP, including the method of PHP. I hope it will be helpful to friends who are interested in PHP tutorials.

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