Guest User

Untitled

a guest
Feb 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. __ __ __ __ __ __ 01
  2. 02 03 04 05 06 07 08
  3. 09 10 11 12 13 14 15
  4. 16 17 18 19 20 21 22
  5. 23 24 25 26 27 28 29
  6. 30 31 __ __ __ __ __
  7.  
  8. <?php
  9. $handle = fopen("input.txt", "r");
  10. list($month,$year) = fscanf($handle, "%d %d");
  11.  
  12. $time = mktime(0, 0, 0, $month, 1, $year);
  13.  
  14. $countDayOfMonth = date('t', $time);
  15. $weekNum = date('w', $time) - 1;
  16. if ($weekNum < 0) $weekNum = 6;
  17.  
  18. $countPlaces = (ceil(($countDayOfMonth + $weekNum) / 7) * 7 - ($countDayOfMonth + $weekNum)) + ($countDayOfMonth + $weekNum);
  19.  
  20. $str = "";
  21. for($i = 1; $i <= $countPlaces; $i++)
  22. {
  23. if( ($i <= $weekNum) OR $i > ($countDayOfMonth + $weekNum))
  24. {
  25. $str .= "__ ";
  26. }else
  27. $str .= str_pad(($i - $weekNum), 2, '0', STR_PAD_LEFT) . " ";
  28.  
  29. if(($i % 7) == 0)
  30. {
  31. $str = trim($str);
  32. if($i < $countPlaces)
  33. $str .= PHP_EOL;
  34. }
  35. }
  36. echo $str;
  37. fclose($handle);
Add Comment
Please, Sign In to add comment