我有一个文本文件,我想读取一个文件并将当前日期写入该文本文件。myfile.txt HELLO WORLD我将在浏览器中打印此文件。现在,我想将当前日期写入文件。
mydate.php
<? php
$file = "myfile.txt"
$handle = fopen($file, "r");
if!($handle){
$date = new DateTime();
fwrite($handle, $date);
fclose($handle);
}
?>
上面是我的PHP脚本,想将当前日期写入文本文件。请帮我将日期写到文件中需要做些什么?谢谢
我想你可以使用file_get_contents
和file_put_contents
$myFile = "myfile.txt";
$myFileContents = file_get_contents($myFile); // $myFileContents now holds the content of myFile.txt
如果要附加当前日期,myFile.txt
可以使用:
$myFile = "myFile.txt";
$myDate = date("m j Y");
file_put_contents($myFile,$myDate, FILE_APPEND);
了解有关file_get_contents,file_put_contents和日期的更多信息
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句