回答編集履歴
1
修正
answer
CHANGED
@@ -8,4 +8,129 @@
|
|
8
8
|
<table class="table table-bordered">
|
9
9
|
```
|
10
10
|
|
11
|
-
`>`で遷移した時のURL見てみると原因わかりますよ。
|
11
|
+
`>`で遷移した時のURL見てみると原因わかりますよ。
|
12
|
+
|
13
|
+
追記:
|
14
|
+
コードインデントはつけられたほうが読みやすいです。
|
15
|
+
コードフォーマット機能のついたエディタ、できればIDE導入を強くすすめます。
|
16
|
+
|
17
|
+
以下はEclipseのコードフォーマットの結果
|
18
|
+
```php
|
19
|
+
<?php
|
20
|
+
date_default_timezone_set('Asia/Tokyo');
|
21
|
+
|
22
|
+
if (isset($_GET['ym'])) {
|
23
|
+
$ym = $_GET['ym'];
|
24
|
+
} else {
|
25
|
+
|
26
|
+
$ym = date('Y-m');
|
27
|
+
}
|
28
|
+
|
29
|
+
$timestamp = strtotime($ym . '-01');
|
30
|
+
if ($timestamp === false) {
|
31
|
+
$ym = date('Y-m');
|
32
|
+
$timestamp = strtotime($ym . '-01');
|
33
|
+
}
|
34
|
+
|
35
|
+
$today = date('Y-m-j', time());
|
36
|
+
|
37
|
+
$html_title = date('Y年n月', $timestamp);
|
38
|
+
|
39
|
+
$prev = date('Y-m', mktime(0, 0, 0, date('m', $timestamp) - 1, 1, date('Y', $timestamp)));
|
40
|
+
$next = date('Y-m', mktime(0, 0, 0, date('m', $timestamp) + 1, 1, date('Y', $timestamp)));
|
41
|
+
|
42
|
+
$day_count = date('t', $timestamp);
|
43
|
+
$youbi = date('w', mktime(0, 0, 0, date('m', $timestamp), 1, date('Y', $timestamp)));
|
44
|
+
$weeks = [];
|
45
|
+
$week = '';
|
46
|
+
$week .= str_repeat('<td></td>', $youbi);
|
47
|
+
|
48
|
+
for ($day = 1; $day <= $day_count; $day ++, $youbi ++) {
|
49
|
+
$date = $ym . '-' . $day;
|
50
|
+
if ($today == $date) {
|
51
|
+
$week .= '<td class="today">' . $day;
|
52
|
+
} else {
|
53
|
+
$week .= '<td>' . $day;
|
54
|
+
}
|
55
|
+
$week .= '</td>';
|
56
|
+
if ($youbi % 7 == 6 || $day == $day_count) {
|
57
|
+
if ($day == $day_count) {
|
58
|
+
$week .= str_repeat('<td></td>', 6 - ($youbi % 7));
|
59
|
+
}
|
60
|
+
$weeks[] = '<tr>' . $week . '</tr>';
|
61
|
+
$week = '';
|
62
|
+
}
|
63
|
+
}
|
64
|
+
?>
|
65
|
+
<!DOCTYPE html>
|
66
|
+
<html lang='ja'>
|
67
|
+
<head>
|
68
|
+
<meta charset='utf-8'>
|
69
|
+
<title>PHPカレンダー</title>
|
70
|
+
<link rel="stylesheet"
|
71
|
+
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
|
72
|
+
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
|
73
|
+
crossorigin="anonymous">
|
74
|
+
|
75
|
+
<link
|
76
|
+
href="https://fonts.googleapis.com/css?family=Noto+Sans+JP&display=swap"
|
77
|
+
rel="stylesheet">
|
78
|
+
<style>
|
79
|
+
.container {
|
80
|
+
font-family: 'Noto Sans JP', sans-serif;
|
81
|
+
margin-top: 80px;
|
82
|
+
}
|
83
|
+
|
84
|
+
h3 {
|
85
|
+
margin-bottom: 30px;
|
86
|
+
}
|
87
|
+
|
88
|
+
th {
|
89
|
+
height: 30px;
|
90
|
+
text-align: center;
|
91
|
+
}
|
92
|
+
|
93
|
+
td {
|
94
|
+
height: 30px;
|
95
|
+
}
|
96
|
+
|
97
|
+
.today {
|
98
|
+
background: green;
|
99
|
+
}
|
100
|
+
|
101
|
+
th:nth-of-type(1), td:nth-of-type(1) {
|
102
|
+
color: red;
|
103
|
+
}
|
104
|
+
|
105
|
+
th:nth-of-type(7), td:nth-of-type(7) {
|
106
|
+
color: blue;
|
107
|
+
}
|
108
|
+
</style>
|
109
|
+
</head>
|
110
|
+
<body>
|
111
|
+
<div class='container'>
|
112
|
+
<h3>
|
113
|
+
<a href="?ym=<?php echo $prev; ?>"><</a> <?php echo $html_title; ?> <a
|
114
|
+
href="?ym=<?php echo $next; ?>">></a>
|
115
|
+
</h3>
|
116
|
+
<table class="table table-bordered">
|
117
|
+
<tr>
|
118
|
+
<th>日</th>
|
119
|
+
<th>月</th>
|
120
|
+
<th>火</th>
|
121
|
+
<th>水</th>
|
122
|
+
<th>木</th>
|
123
|
+
<th>金</th>
|
124
|
+
<th>土</th>
|
125
|
+
|
126
|
+
</tr>
|
127
|
+
<?php
|
128
|
+
foreach($weeks as $week){
|
129
|
+
echo $week;
|
130
|
+
}
|
131
|
+
?>
|
132
|
+
</table>
|
133
|
+
</div>
|
134
|
+
</body>
|
135
|
+
</html>
|
136
|
+
```
|