Home > Backend Development > PHP Tutorial > Simple calendar implementation

Simple calendar implementation

WBOY
Release: 2016-07-25 09:11:08
Original
986 people have browsed it
A simple calendar implementation. I don’t know if there is any problem with the implementation method of this code. I didn’t refer to my predecessors. After you understand my bad code, it will be more helpful to appreciate other people’s excellent code.
  1. $date = isset( $_GET['d']) ? intval($_GET['d']) : '';
  2. if($date)
  3. {
  4. $y = substr($date,0,4);
  5. $m = substr ($date,4,2);
  6. $cur = mktime(0,0,0,$m,1,$y);
  7. }
  8. else
  9. {
  10. $cur = mktime();
  11. }
  12. list( $year,$month,$day) = explode('-',date('Y-m-d',$cur));//Year, month and day
  13. $p = date('Ym',strtotime('last months' ,$cur));//The previous month
  14. $n = date('Ym',strtotime('next months',$cur));//The next month
  15. $t = date('t',$cur ); //How many days in the month
  16. $s = date('w',mktime(0,0,0,$month,1,$year)); //Padding blanks
  17. $e = 6-(date(' w',mktime(0,0,0,$month,$t,$year)));//Fill in the blanks
  18. ?>
  19. «  yearmonth  »
  20. < td>One< td>六
  21. echo '
  22. ';
  23. for($i=0;$i<$s;$i++)
  24. {
  25. echo '
  26. ';
  27. }
  28. for($d=1;$d<=$t;$d++)
  29. {
  30. $current=$d==$day ?'class="current"':'';//Current style
  31. $r = ($d+$s)%7;//Line break
  32. echo "
  33. " ;
  34. if($r==0)
  35. {
  36. echo '
  37. ';
  38. echo '
  39. ';
  40. }
  41. }
  42. for($i=0;$ i<$e;$i++)
  43. {
  44. echo '
  45. ';
  46. }
  47. ?>
  48. dayTwoThreeFourFive
      $d
     
Copy code


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template