SHARE
TWEET

Ego Ticker PHP Change

MattRichardson Jan 16th, 2012 36 Never
  1. <?php
  2. date_default_timezone_set('America/New_York');
  3. $myFileYesterday = "reddit-" . date("Ymd", time() - 86400). ".txt";
  4. $myFileToday = "reddit-" . date("Ymd"). ".txt";
  5. $fhYesterday = fopen($myFileYesterday, 'r');
  6. $fhToday = fopen($myFileToday, 'r');
  7. $yesterdayScore = fread($fhYesterday, 50);
  8. $todayScore = fread($fhToday, 50);
  9. $change = $todayScore - $yesterdayScore;
  10. if ($change == 0)
  11.         echo "Unch";
  12. if ($change > 0)
  13. {
  14.         echo "+";
  15.         echo $change;
  16.         }
  17. if ($change < 0)
  18. {
  19.         echo $change;
  20. }
  21.  
  22. fclose($fhToday);
  23. fclose($fhYesterday);
  24.  
  25. $checkfile = "reddit-" . date("Ymd", time() - 172800). ".txt";
  26.  
  27. if (is_file($checkfile)) {
  28.         unlink($checkfile);
  29. }
  30. ?>
RAW Paste Data
Top