質問編集履歴
1
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
|
23
23
|
PHP
|
24
24
|
ソースコード
|
25
|
+
```PHP
|
25
26
|
<!DOCTYPE html>
|
26
27
|
<html lang="ja">
|
27
28
|
<head>
|
@@ -31,11 +32,10 @@
|
|
31
32
|
<body>
|
32
33
|
|
33
34
|
<form action="" method="post">
|
34
|
-
|
35
|
+
<input type="text" name="namae" value="名前">
|
35
|
-
|
36
|
+
<input type="text" name="comment" value="コメント">
|
36
|
-
|
37
|
+
<input type="submit" name="sousin">
|
37
|
-
|
38
|
-
</form>
|
38
|
+
</form>
|
39
39
|
|
40
40
|
<?php
|
41
41
|
$filename="mission_3-1.txt";
|
@@ -47,26 +47,27 @@
|
|
47
47
|
$date = date("Y年m月d日 H:i:s");
|
48
48
|
//ファイルの存在がある場合は投稿番号+1、なかったら1を指定する
|
49
49
|
if (file_exists($filename)) {
|
50
|
-
|
50
|
+
$n = explode("<>",$filename);
|
51
|
-
|
51
|
+
for($a=0; $a<$filename;$a++){
|
52
|
-
|
52
|
+
$nu = $n[$a];
|
53
|
-
|
53
|
+
$num = $nu[0];
|
54
|
-
|
54
|
+
}
|
55
55
|
} else {
|
56
56
|
$num = 1;
|
57
|
-
}
|
57
|
+
}
|
58
58
|
//書き込む文字列を組み合わせた変数
|
59
59
|
$format = $num."<>".$namae."<>".$comment."<>".$date;
|
60
60
|
|
61
61
|
//もしフォームが空じゃなかったら書き込みをする
|
62
62
|
if (!empty($namae)||!empty($comment)){
|
63
|
-
|
63
|
+
$fp = fopen($filename,'a');
|
64
|
-
|
64
|
+
fwrite($fp, $format."\n");
|
65
|
-
|
65
|
+
fclose($fp);
|
66
|
-
}
|
66
|
+
}
|
67
67
|
?>
|
68
68
|
</body>
|
69
69
|
</html>
|
70
|
+
```
|
70
71
|
|
71
72
|
### 試したこと
|
72
73
|
|