How do I write to a file in php?

☆樱花仙子☆ 提交于 2019-12-11 14:12:15

问题


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:


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)



来源:https://stackoverflow.com/questions/9752904/how-do-i-write-to-a-file-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!