How do I write to a file in php?

2019-09-11 12:57发布

I am getting the source of a page as follows:

<? $txt = file_get_contents('http://stats.pingdom.com/file');
echo $txt; ?>

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.)

How could I do this?

1条回答
对你真心纯属浪费
2楼-- · 2019-09-11 13:20

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);

To run it every minute, look at something like cron (or its equivalent on your operating platform of choice)

查看更多
登录 后发表回答