如何在php中写入文件? [英] How do I write to a file in php?
本文介绍了如何在php中写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在获取页面的来源,如下所示:
I am getting the source of a page as follows:
<? $txt = file_get_contents('http://stats.pingdom.com/file');
echo $txt; ?>
并将其打印在屏幕上,但老实说,我实际上想每1分钟用它替换一个现有的html文件. (我将每1分钟打开一次文件.)
and printing it on the screen but to be honest I actually want to replace an existing html file with it every 1 min. (I will be opening the file every 1 min.)
我该怎么办?
推荐答案
如果您已学会使用file_get_contents(),请考虑使用其姐妹函数
If you've learned to use file_get_contents() then consider his sister function file_put_contents()
$txt = file_get_contents('http://stats.pingdom.com/file');
file_put_contents('/path/to/my/file.html',$txt);
要每分钟运行一次,请查看类似cron的内容(或在您选择的操作平台上看到的内容)
To run it every minute, look at something like cron (or its equivalent on your operating platform of choice)
这篇关于如何在php中写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文