回答編集履歴
1
調整
test
CHANGED
@@ -3,3 +3,30 @@
|
|
3
3
|
- JSONデータを取得したらjson_decodeで配列で保持
|
4
4
|
- 新規データをarray_push
|
5
5
|
- json_encodeしてJSONファイルに上書き
|
6
|
+
|
7
|
+
# 参考
|
8
|
+
|
9
|
+
```PHP
|
10
|
+
<?PHP
|
11
|
+
$id =filter_input(INPUT_POST,"id");
|
12
|
+
$password=filter_input(INPUT_POST,"password");
|
13
|
+
$content =filter_input(INPUT_POST,"content");
|
14
|
+
if(!empty($id) and !empty($password) and !empty($content)){
|
15
|
+
$json = file_get_contents('pswd.json');
|
16
|
+
$json = preg_replace("/\A\xEF\xBB\xBF/","",$json); //念の為BOMを除去
|
17
|
+
$json = json_decode($json,JSON_OBJECT_AS_ARRAY);
|
18
|
+
array_push($json,["id"=>$id,"password"=>$password,"content"=>$content]);
|
19
|
+
print "<pre>";
|
20
|
+
print json_encode($json, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT );
|
21
|
+
exit;
|
22
|
+
}
|
23
|
+
?>
|
24
|
+
<form method="post">
|
25
|
+
<dl>
|
26
|
+
<dt>ID:</dt><dd><input name="id" value="1"></dd>
|
27
|
+
<dt>PASS:</dt><dd><input name="password" value="2"></dd>
|
28
|
+
<dt>CONTENT:</dt><dd><input name="content" value="3"></dd>
|
29
|
+
</dl>
|
30
|
+
<input type="submit" value="send">
|
31
|
+
</form>
|
32
|
+
```
|