回答編集履歴
1
追記
answer
CHANGED
@@ -2,4 +2,95 @@
|
|
2
2
|
|
3
3
|
```php
|
4
4
|
date('m/d', strtotime('last day of July 2008'));
|
5
|
+
```
|
6
|
+
|
7
|
+
#サンプル
|
8
|
+
|
9
|
+
```php
|
10
|
+
<?php
|
11
|
+
ini_set('display_errors', true);
|
12
|
+
error_reporting(E_ALL);
|
13
|
+
|
14
|
+
function weekday(DateTime $dt)
|
15
|
+
{
|
16
|
+
$weeks = ['日', '月', '火', '水', '木', '金', '土'];
|
17
|
+
return $weeks[$dt->format('w')];
|
18
|
+
}
|
19
|
+
|
20
|
+
$dt = new DateTime('first day of this month');
|
21
|
+
|
22
|
+
if (filter_input(INPUT_POST, 'y') && filter_input(INPUT_POST, 'm')) {
|
23
|
+
$year = filter_input(INPUT_POST, 'y');
|
24
|
+
$month = filter_input(INPUT_POST, 'm');
|
25
|
+
$dt = new DateTime(sprintf('%d-%d-01', $year, $month));
|
26
|
+
}
|
27
|
+
|
28
|
+
$month = $dt->format('m');
|
29
|
+
?>
|
30
|
+
<!DOCTYPE html>
|
31
|
+
<html>
|
32
|
+
<head>
|
33
|
+
<meta charset="UTF-8">
|
34
|
+
<title></title>
|
35
|
+
<style type="text/css">
|
36
|
+
body > div {
|
37
|
+
margin: 1em 0;
|
38
|
+
}
|
39
|
+
table {
|
40
|
+
border-collapse: collapse;
|
41
|
+
}
|
42
|
+
table th, table td {
|
43
|
+
border: 1px solid #CCC;
|
44
|
+
}
|
45
|
+
</style>
|
46
|
+
</head>
|
47
|
+
<body>
|
48
|
+
<div>
|
49
|
+
<form action="" method="post">
|
50
|
+
<select name="y">
|
51
|
+
<?php foreach (range(2016, 2017) as $y): ?>
|
52
|
+
<?php if ((new DateTime())->format('Y') == $y) : ?>
|
53
|
+
<option value="<?= $y; ?>" selected="selected"><?= $y; ?></option>
|
54
|
+
<?php else : ?>
|
55
|
+
<option value="<?= $y; ?>"><?= $y; ?></option>
|
56
|
+
<?php endif; ?>
|
57
|
+
<?php endforeach; ?>
|
58
|
+
</select>
|
59
|
+
<select name="m">
|
60
|
+
<?php foreach (range(1, 12) as $m): ?>
|
61
|
+
<?php if ((new DateTime())->format('m') == $m) : ?>
|
62
|
+
<option value="<?= $m; ?>" selected="selected"><?= $m; ?></option>
|
63
|
+
<?php else : ?>
|
64
|
+
<option value="<?= $m; ?>"><?= $m; ?></option>
|
65
|
+
<?php endif; ?>
|
66
|
+
<?php endforeach; ?>
|
67
|
+
</select>
|
68
|
+
<button>変更</button>
|
69
|
+
</form>
|
70
|
+
</div>
|
71
|
+
<div>
|
72
|
+
<table>
|
73
|
+
<thead>
|
74
|
+
<tr>
|
75
|
+
<th>年</th>
|
76
|
+
<th>月</th>
|
77
|
+
<th>日</th>
|
78
|
+
<th>曜日</th>
|
79
|
+
</tr>
|
80
|
+
</thead>
|
81
|
+
<tbody>
|
82
|
+
<?php while ($month == $dt->format('m')): ?>
|
83
|
+
<tr>
|
84
|
+
<td><?= $dt->format('Y'); ?></td>
|
85
|
+
<td><?= $dt->format('m'); ?></td>
|
86
|
+
<td><?= $dt->format('d'); ?></td>
|
87
|
+
<td><?= weekday($dt); ?></td>
|
88
|
+
</tr>
|
89
|
+
<?php $dt->add(new DateInterval('P1D')) ?>
|
90
|
+
<?php endwhile; ?>
|
91
|
+
</tbody>
|
92
|
+
</table>
|
93
|
+
</div>
|
94
|
+
</body>
|
95
|
+
</html>
|
5
96
|
```
|