-3

我想在php文件上记录文件的执行.txt
我希望文件看起来像这样的序列号:

1, (time)
2, (time)
3, (time)
. . . . .
. . . . .

其中 (time) 是php文件的执行时间。

如何将序列号添加到每一行以及如何将每个条目放在下一行?

$today = date("Y-m-d H:i:s"); 
$file = fopen("log.txt","a+");
fwrite($file,$today);
fclose($file);
4

2 回答 2

2
  1. 在您的服务器/计算机上创建您的文件,与您放置 PHP 文件的位置相同。在此示例中,我们将其称为“log.txt”
  2. 做你必须做的使文件可写。对于此示例,您只需在 Filezilla 中右键单击它并选择“权限”,然后将其更改为 777,或谷歌如何使用chmod.
  3. 在您的脚本中,粘贴以下代码:

    $fh = fopen("log.txt","a+");

    fwrite($fh, date("Ymd g:i a")."\r\n");

    fclose($fh);

http://php.net/manual/en/function.fopen.php

http://php.net/manual/en/function.fwrite.php

于 2015-06-09T11:59:53.807 回答
0

由于您没有提供任何代码,因此这里是有关如何执行此操作的提示:

File_Put_Contents('../file path/yourlog.txt',$yourfilecontent, FILE_APPEND);
于 2015-06-09T11:58:13.807 回答