如果有文件 ex (news.txt)
而且我需要 php 来每天阅读我在这个文件中的文字
每天php只读一行>>
我写了这段代码,但它不起作用 >>>任何帮助
$wordfile = "words.txt";
$open = fopen($wordfile, "r");
$read = fread($open, filesize($wordfile));
fclose($wordfile);
$array = explode("\n",$read);
$date = date("z");
while ($date++){
echo $array;
}
最佳答案
$f = file("words.txt");
echo $f[date("z")];
就这么简单,假设您有一个包含 366 行的文件。您的代码的问题是循环永远不会结束。您可能想要 while ($date--)
然后在循环中做一些改变“当前行”的事情。
关于php - 需要按日期逐行阅读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3237125/