yuhsing

Untitled

Feb 17th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2. function generateDatePicker()
  3. {
  4. $months = array(
  5. 1 => "January", "February", "March", "April", "May", "June",
  6. "July", "August", "September", "October", "November", "December"
  7. );
  8.  
  9. date_default_timezone_set('Asia/Kuala_Lumpur');
  10. $today = getdate();
  11. $cur_day = $today['mday'];
  12. $cur_month = $today['mon'];
  13. $cur_year = $today['year'];
  14.  
  15. // Generate days.
  16. echo '<select name="day">';
  17. for ($d = 1; $d <= 31; $d++)
  18. {
  19. printf('<option %s>%d</option>',
  20. $d == $cur_day ? 'selected="selected"' : '',
  21. $d
  22. );
  23. }
  24. echo '</select> ';
  25.  
  26. // Generate months.
  27. echo '<select name="month">';
  28. foreach ($months as $key => $value)
  29. {
  30. printf('<option %s value="%d">%s</option>',
  31. $key == $cur_month ? 'selected="selected"' : '',
  32. $key,
  33. $value
  34. );
  35. }
  36. echo '</select> ';
  37.  
  38. // Generate years.
  39. echo '<select name="year">';
  40. for ($y = $cur_year - 20; $y <= $cur_year; $y++)
  41. {
  42. printf('<option %s>%d</option>',
  43. $y == $cur_year ? 'selected="selected"' : '',
  44. $y
  45. );
  46. }
  47. echo '</select> ';
  48. }
  49. ?>
  50. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  51. <html>
  52. <head>
  53. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  54. <title>P1Q8</title>
  55. <link rel="stylesheet" type="text/css" href="style.css" />
  56. </head>
  57. <body>
  58. <?php
  59. generateDatePicker();
  60. ?>
  61.  
  62. <p>
  63. [ <a href="index.php">Back</a> ]
  64. </p>
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment