如何在 php 执行时将当前时间写入 .txt 文件的新行
How to write the current time to a new line of a .txt file on php execution
我想在 .txt
文件上记录 php
文件的执行。
我希望文件看起来像这样,序列号为:
1, (time)
2, (time)
3, (time)
. . . . .
. . . . .
其中(时间)是 php
文件的执行时间。
如何将序列号添加到每一行以及如何将每个条目放在下一行?
$today = date("Y-m-d H:i:s");
$file = fopen("log.txt","a+");
fwrite($file,$today);
fclose($file);
由于您没有提供任何代码,这里有一个关于如何做到这一点的提示:
File_Put_Contents('../file path/yourlog.txt',$yourfilecontent, FILE_APPEND);
- 在 server/computer 上创建文件,与放置 PHP 文件的位置相同。在这个例子中,我们称它为 "log.txt"
- 执行您必须执行的操作以使文件可写。对于这个例子,你可以在Filezilla中右击它并选择"permissions",然后把它改成777,或者Google 如何使用
chmod
.
在您的脚本中,粘贴以下代码:
$fh = fopen("log.txt","a+");
fwrite($fh, date("Y-m-d g:i a")."\r\n");
fclose($fh);
我想在 .txt
文件上记录 php
文件的执行。
我希望文件看起来像这样,序列号为:
1, (time)
2, (time)
3, (time)
. . . . .
. . . . .
其中(时间)是 php
文件的执行时间。
如何将序列号添加到每一行以及如何将每个条目放在下一行?
$today = date("Y-m-d H:i:s");
$file = fopen("log.txt","a+");
fwrite($file,$today);
fclose($file);
由于您没有提供任何代码,这里有一个关于如何做到这一点的提示:
File_Put_Contents('../file path/yourlog.txt',$yourfilecontent, FILE_APPEND);
- 在 server/computer 上创建文件,与放置 PHP 文件的位置相同。在这个例子中,我们称它为 "log.txt"
- 执行您必须执行的操作以使文件可写。对于这个例子,你可以在Filezilla中右击它并选择"permissions",然后把它改成777,或者Google 如何使用
chmod
. 在您的脚本中,粘贴以下代码:
$fh = fopen("log.txt","a+");
fwrite($fh, date("Y-m-d g:i a")."\r\n");
fclose($fh);