<?
$filename = "arraytext.txt";
$f = fopen($filename, 'r');
echo fgets($f);
fclose($f);
?>
要运行它每12小时,这条线添加到您的“/ etc/crontab中”文件(例如):
00 11,23 * * * root php path-to-your-script/name-of-your-script.php
UPDATE:您的评论后,我想我更好地理解你的问题(所以RRY)。
忘掉“的crontab”的东西...
只要做到:
<?
$filename = "arraytext.txt";
$arr = file($filename);
foreach ($arr as $line) {
print $line . "<br />";
sleep(60 * 60 * 12); // (60 * 60) * 12 seconds sums up to 12 hours
}
?>
被警告,虽然,PHP在“网络”模式下运行(而不是“CLI”模式)有严格的执行时间限制(见http://php.net/manual/en/function.set-time-limit.php)。
我想你是在网络接口上使用这个,因为在你的问题,你使用HTML标签<br />
...
注:很抱歉,但为什么你想写一个线的每个12小时? ? :-)
'foreach'将遍历所有行。也许你想阅读[最快的方式来从文件中读取第一行](http://stackoverflow.com/a/4521969/1983854) – fedorqui 2014-11-03 15:12:31
$ f = fopen($ file,'r'); $ line = fgets($ f); fclose($ f); 这只会读一行吗? – spurrenirre 2014-11-03 15:14:30
它应该。但你自己测试:) – fedorqui 2014-11-03 15:16:52