清除txt文件中的所有数据 - php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5650958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
erase all data from txt file - php
提问by blasteralfred Ψ
Possible Duplicate:
How do i purge the contents of a text file in php
可能的重复:
我如何清除 php 中文本文件的内容
Hi..
你好..
How can I erase all the data stored (make blank) in my text file myfile.txt
using php??
如何myfile.txt
使用 php删除文本文件中存储的所有数据(将其设为空白)?
回答by Robik
PHP's file_put_contents()
should be usefull in this case. Here's some example code:
file_put_contents()
在这种情况下,PHP应该很有用。下面是一些示例代码:
file_put_contents('myfile.txt', '');
回答by oezi
$handle = fopen ("/path/to/file.txt", "w+");
fclose($handle);
take a look at the documentationfor more info.
查看文档以获取更多信息。
回答by Chris Eberle
<?php
file_put_contents("myfile.txt", "");
?>
回答by Oswald
$file = fopen('myfile.txt', 'w');
fclose($file);
回答by ianace
$handle = fopen("myfile.txt", "w+");
fwrite($handle , '');
fclose($handle);
回答by David
$myFile = "myFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "");
fclose($fh);