First Friday script updated and simplified

NOTE: The latest version of this script can always be found here: http://github.com/PHLAK/first-friday/blob/master/first-friday.php

With this update I have drastically reduced and simpified the code to produce the same results.  I did some rigorous testing of my own to make sure this script will calculate the correct date, but that doesn’t mean it’s bullet-proof.  If you find a bug, please email me so I can fix it.

first-friday.php

 
  // Calculate next Friday
  for ($x = date('d'); $x <= (date('d') + 6); $x++) {
    $timeStamp = mktime(0,0,0,date('m'),$x,date('Y'));
    if (date('w',$timeStamp) == 5) {
      $nextFriday = mktime(0,0,0,date('m'),$x,date('Y'));
    }
  }
  // Check if next Friday is the first friday of the month.
  if (date('d', $nextFriday) <= 7) {
    $firstFriday = $nextFriday;
  } else {
  // Calculate first Friday of next month
    for ($x = 1; $x <= 7; $x++) {
      $timeStamp = mktime(0,0,0,date('m')+1,$x,date('Y'));
      if (date('w',$timeStamp) == 5) {
        $firstFriday = mktime(0,0,0,date('m')+1,$x,date('Y'));
      }
    }
  }
 
  // Echo next first Friday
  echo date("F j, Y", $firstFriday);
 
?>