質問編集履歴
5
誤字を修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -31,7 +31,7 @@
|
|
31
31
|
<form action="save.php" method="post">
|
32
32
|
<input type="hidden" name="textarea" value="<?php echo $textarea; ?>">
|
33
33
|
<button type="button" onclick="history.back()">戻る</button>
|
34
|
-
<button type="submit"
|
34
|
+
<button type="submit">更新</button>
|
35
35
|
</form>
|
36
36
|
```
|
37
37
|
save.php内では
|
4
title
CHANGED
File without changes
|
body
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
file_put_contents ($file, json_encode($textarea));
|
43
43
|
```
|
44
44
|
```html
|
45
|
-
<p
|
45
|
+
<p>更新完了</p>
|
46
46
|
<a href="output.php">更新を確認</a>
|
47
47
|
```
|
48
48
|
|
3
title
CHANGED
File without changes
|
body
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
```
|
28
28
|
```html
|
29
29
|
<p>入力内容を確認してください</p>
|
30
|
-
<p><?php echo $
|
30
|
+
<p><?php echo $textarea; ?></p>
|
31
31
|
<form action="save.php" method="post">
|
32
32
|
<input type="hidden" name="textarea" value="<?php echo $textarea; ?>">
|
33
33
|
<button type="button" onclick="history.back()">戻る</button>
|
2
htmlを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,29 +1,60 @@
|
|
1
1
|
input.phpの<textarea>フォームから、
|
2
2
|
入力された内容を改行まで入力された通りにoutput.phpで表示できるようにしたいです。
|
3
3
|
|
4
|
+
input.phpで入力
|
5
|
+
↓
|
6
|
+
confirm.phpで確認表示
|
7
|
+
↓
|
4
|
-
|
8
|
+
save.phpで入力内容をtxtファイルに保存
|
9
|
+
↓
|
5
|
-
output.phpでtxtファイルから
|
10
|
+
output.phpでtxtファイルからファイル内容を表示
|
6
|
-
という流れになってます。
|
7
11
|
|
12
|
+
という流れです。
|
13
|
+
|
8
14
|
現在、
|
15
|
+
input.php
|
16
|
+
```html
|
17
|
+
<form action="confirm.php" method="post">
|
18
|
+
<textarea name="textarea"></textarea>
|
19
|
+
<button type="submit">確認</button>
|
20
|
+
</form>
|
21
|
+
```
|
9
|
-
confirm.php
|
22
|
+
confirm.php
|
10
23
|
```php
|
11
24
|
$textarea = $_POST['textarea'];
|
12
25
|
$textarea = htmlspecialchars($textarea);
|
13
26
|
$textarea = nl2br($textarea);
|
14
27
|
```
|
28
|
+
```html
|
29
|
+
<p>入力内容を確認してください</p>
|
30
|
+
<p><?php echo $message; ?></p>
|
31
|
+
<form action="save.php" method="post">
|
32
|
+
<input type="hidden" name="textarea" value="<?php echo $textarea; ?>">
|
33
|
+
<button type="button" onclick="history.back()">戻る</button>
|
34
|
+
<button type="submit" class="btn btn-light border" style="width:150px;">更新</button>
|
35
|
+
</form>
|
36
|
+
```
|
15
37
|
save.php内では
|
16
38
|
```php
|
17
39
|
$textarea = $_POST['textarea'];
|
18
40
|
$textarea = htmlspecialchars($textarea);
|
19
41
|
$file = 'file.txt';
|
20
|
-
|
42
|
+
file_put_contents ($file, json_encode($textarea));
|
21
43
|
```
|
44
|
+
```html
|
45
|
+
<p class="h4 text-center my-5">更新完了</p>
|
46
|
+
<a href="output.php">更新を確認</a>
|
47
|
+
```
|
48
|
+
|
22
49
|
output.php内では
|
23
50
|
```php
|
51
|
+
$file='file.txt';
|
52
|
+
if (file_exists($file)){
|
53
|
+
$textarea = json_decode(file_get_contents($file));
|
24
|
-
echo '<p>'.$textarea.'</p>';
|
54
|
+
echo '<p>'.$textarea.'</p>';
|
55
|
+
}
|
25
56
|
```
|
26
|
-
と
|
57
|
+
となっております。
|
27
58
|
|
28
59
|
例えば、
|
29
60
|
input.phpで
|
@@ -43,4 +74,11 @@
|
|
43
74
|
echo '<p>'.htmlspecialchars($textarea).'</p>';
|
44
75
|
```
|
45
76
|
にする等変更してみましたがうまくいきません。
|
46
|
-
どうすればタグが表示されず、改行もできるようになるのでしょうか?
|
77
|
+
どうすればタグが表示されず、改行もできるようになるのでしょうか?
|
78
|
+
|
79
|
+
///////////////////////
|
80
|
+
htmlを追記しました。
|
81
|
+
初心者なので、以上で必要な情報が揃っているかもわかりませんが、
|
82
|
+
仕事で必要に迫られ、周りにわかる者もいない中で悩みながら作っております。
|
83
|
+
業務の都合上、抜粋での記載となり申し訳ありません。
|
84
|
+
どうぞよろしくお願いします。
|
1
保存するファイルのソースを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
input.phpの<textarea>フォームから、
|
2
2
|
入力された内容を改行まで入力された通りにoutput.phpで表示できるようにしたいです。
|
3
3
|
|
4
|
+
input.phpで入力→confirm.phpで確認表示→save.phpでfile_put_contentsを使って入力内容をtxtファイルに保存→
|
5
|
+
output.phpでtxtファイルからfile_get_contentsで表示
|
6
|
+
という流れになってます。
|
7
|
+
|
4
8
|
現在、
|
5
9
|
confirm.php内では
|
6
10
|
```php
|
@@ -8,6 +12,13 @@
|
|
8
12
|
$textarea = htmlspecialchars($textarea);
|
9
13
|
$textarea = nl2br($textarea);
|
10
14
|
```
|
15
|
+
save.php内では
|
16
|
+
```php
|
17
|
+
$textarea = $_POST['textarea'];
|
18
|
+
$textarea = htmlspecialchars($textarea);
|
19
|
+
$file = 'file.txt';
|
20
|
+
file_put_contents ($file, json_encode($textarea));
|
21
|
+
```
|
11
22
|
output.php内では
|
12
23
|
```php
|
13
24
|
echo '<p>'.$textarea.'</p>';
|