-2

I'm asking because I'd like to have a graph with historical data, including from the most updated date. I know how to save scraped data as a certain name, and have it saved into a cache folder.

If it's possible instead of saying...save current file as _____.php in cache folder, to something like...[current date].php, etc. Not sure if php is possible of this. Is there a way? And likewise, if that worked, file would be named, using today as an example 7-1-2017.php

Thanks very much.

Masteryogurt
  • 199
  • 4
  • 14

1 Answers1

1

Yes PHP can do that :) The most simple and hacky way I can think of would be:

file_put_contents(date('n-j-Y') .'.php', file_get_contents('http://example.com'));

I may also suggest you to use cURL or Guzzle to be able to catch errors, etc ...

Pascal Meunier
  • 685
  • 6
  • 15
  • I'm using this sort of coding. file_put_contents(globalVars::$_cache_dir . "london", $ret_[24]); with your suggestion in mind, would you mind letting me know what I'm doing wrong. Doesn't work, which I'm not surprised about, still very new to php, trying to get better. Mostly mess up formatting these days. file_put_contents(globalVars::$_cache_dir . "(n-j-Y') .'.php'", $ret_[24]); – Masteryogurt Jul 02 '17 at 00:44
  • I should clarify, it just saves the php name as n-j-Y.php – Masteryogurt Jul 02 '17 at 00:44
  • Here: `file_put_contents(globalVars::$_cache_dir . date('n-j-Y') .'.php', $ret_[24]);` – Pascal Meunier Jul 02 '17 at 00:46
  • Hey! Thanks Pascal, that works. Thanks so much, you've been amazingly helpful. Funny, it actually saves it as 7-2, even though it's 7-1 here in USA,. Why do you think that is? Php based geographically one day ahead perhaps lol. – Masteryogurt Jul 02 '17 at 00:49
  • figured it out, guess it's something to do with my hosting server location. i can specify time date in code it would seem – Masteryogurt Jul 02 '17 at 00:53
  • Most servers are setup to be UTC. Rather than use date, you should use a DateTime. – gview Jul 02 '17 at 17:31