如何在php中写入文件?
问题描述:
我得到一个页面的源代码如下:如何在php中写入文件?
<? $txt = file_get_contents('http://stats.pingdom.com/file');
echo $txt; ?>
并打印在屏幕上,但说实话其实我是想取代其现有的HTML文件中的每个1分钟。 (我将每1分钟打开一次文件)
我该怎么做?
答
如果你已经学会了使用的file_get_contents()再考虑他的妹妹功能file_put_contents()
$txt = file_get_contents('http://stats.pingdom.com/file');
file_put_contents('/path/to/my/file.html',$txt);
要运行它的每一分钟,看东西比如cron(或等值您选择的操作平台上)
为什么你甚至需要一个PHP脚本来做到这一点?您是否尝试过使用'wget http://stats.pingdom.com/file -o/path/to/the/file/locally',并将其添加到您的crontab */1 * * * *'中以便每分钟运行一次? – 2012-03-17 19:24:00