回答編集履歴

1

追記

2017/02/16 14:34

投稿

退会済みユーザー
test CHANGED
@@ -7,3 +7,185 @@
7
7
  date('m/d', strtotime('last day of July 2008'));
8
8
 
9
9
  ```
10
+
11
+
12
+
13
+ #サンプル
14
+
15
+
16
+
17
+ ```php
18
+
19
+ <?php
20
+
21
+ ini_set('display_errors', true);
22
+
23
+ error_reporting(E_ALL);
24
+
25
+
26
+
27
+ function weekday(DateTime $dt)
28
+
29
+ {
30
+
31
+ $weeks = ['日', '月', '火', '水', '木', '金', '土'];
32
+
33
+ return $weeks[$dt->format('w')];
34
+
35
+ }
36
+
37
+
38
+
39
+ $dt = new DateTime('first day of this month');
40
+
41
+
42
+
43
+ if (filter_input(INPUT_POST, 'y') && filter_input(INPUT_POST, 'm')) {
44
+
45
+ $year = filter_input(INPUT_POST, 'y');
46
+
47
+ $month = filter_input(INPUT_POST, 'm');
48
+
49
+ $dt = new DateTime(sprintf('%d-%d-01', $year, $month));
50
+
51
+ }
52
+
53
+
54
+
55
+ $month = $dt->format('m');
56
+
57
+ ?>
58
+
59
+ <!DOCTYPE html>
60
+
61
+ <html>
62
+
63
+ <head>
64
+
65
+ <meta charset="UTF-8">
66
+
67
+ <title></title>
68
+
69
+ <style type="text/css">
70
+
71
+ body > div {
72
+
73
+ margin: 1em 0;
74
+
75
+ }
76
+
77
+ table {
78
+
79
+ border-collapse: collapse;
80
+
81
+ }
82
+
83
+ table th, table td {
84
+
85
+ border: 1px solid #CCC;
86
+
87
+ }
88
+
89
+ </style>
90
+
91
+ </head>
92
+
93
+ <body>
94
+
95
+ <div>
96
+
97
+ <form action="" method="post">
98
+
99
+ <select name="y">
100
+
101
+ <?php foreach (range(2016, 2017) as $y): ?>
102
+
103
+ <?php if ((new DateTime())->format('Y') == $y) : ?>
104
+
105
+ <option value="<?= $y; ?>" selected="selected"><?= $y; ?></option>
106
+
107
+ <?php else : ?>
108
+
109
+ <option value="<?= $y; ?>"><?= $y; ?></option>
110
+
111
+ <?php endif; ?>
112
+
113
+ <?php endforeach; ?>
114
+
115
+ </select>
116
+
117
+ <select name="m">
118
+
119
+ <?php foreach (range(1, 12) as $m): ?>
120
+
121
+ <?php if ((new DateTime())->format('m') == $m) : ?>
122
+
123
+ <option value="<?= $m; ?>" selected="selected"><?= $m; ?></option>
124
+
125
+ <?php else : ?>
126
+
127
+ <option value="<?= $m; ?>"><?= $m; ?></option>
128
+
129
+ <?php endif; ?>
130
+
131
+ <?php endforeach; ?>
132
+
133
+ </select>
134
+
135
+ <button>変更</button>
136
+
137
+ </form>
138
+
139
+ </div>
140
+
141
+ <div>
142
+
143
+ <table>
144
+
145
+ <thead>
146
+
147
+ <tr>
148
+
149
+ <th>年</th>
150
+
151
+ <th>月</th>
152
+
153
+ <th>日</th>
154
+
155
+ <th>曜日</th>
156
+
157
+ </tr>
158
+
159
+ </thead>
160
+
161
+ <tbody>
162
+
163
+ <?php while ($month == $dt->format('m')): ?>
164
+
165
+ <tr>
166
+
167
+ <td><?= $dt->format('Y'); ?></td>
168
+
169
+ <td><?= $dt->format('m'); ?></td>
170
+
171
+ <td><?= $dt->format('d'); ?></td>
172
+
173
+ <td><?= weekday($dt); ?></td>
174
+
175
+ </tr>
176
+
177
+ <?php $dt->add(new DateInterval('P1D')) ?>
178
+
179
+ <?php endwhile; ?>
180
+
181
+ </tbody>
182
+
183
+ </table>
184
+
185
+ </div>
186
+
187
+ </body>
188
+
189
+ </html>
190
+
191
+ ```