1 回答
TA贡献1802条经验 获得超4个赞
由于您必须为每个访问者读取文件以显示文本的第一行,因此您可以根据需要编写一些代码来修改文件。
假设你有这个文件:
2019-05-12
This is line 1
This is line 2
This is line 3
然后为每个访问者包含这件作品:
$text = file('myfile.txt'); // read file into array
$date = $text[0]; // get the last update date
$now = date('Y-m-d',time()); // today
$show = 1; // 1 = first text line in array
//if we need to update
if( $date !== $now ){
$show = 2; // 2 = we need a new line
$text[0] = $now; // set last update to today
unset($text[1]); // delete the old line
// write back file without the deleted line
file_put_contents('myfile.txt', implode("\n",$text);
}
echo $text[$show];
没有测试代码,但你明白了
- 1 回答
- 0 关注
- 161 浏览
添加回答
举报