htmlのフォームから取得した文字をjsonファイルに代入したいんですがカッコを最低限の数にしたいです。どうすれば良いでしょうか。
該当のソースコード
html
1<html> 2<head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 3 <title>input.html</title></head> 4<body> 5 6<form action="output.php" method="post"> 7 <table border="1"> 8 <tr> 9 <td><input type="text" name="message1"></td> 10<td><input type="text" name="message2"></td> 11 <input type="submit" value="入力"> 12 </tr> 13 </table> 14</form> 15</body> 16</html>
PHP
1<html> 2<head><title></title></head> 3<body> 4<?php 5touch('message.json'); 6$json = file_get_contents('message.json'); 7$records = (array)json_decode($json, true); 8$message_post1 = $_POST['message1']; 9$message_post2 = $_POST['message2']; 10 11$records[] = array( 12 $message_post1 => $message_post2 13); 14 15$out_json = json_encode($records,JSON_UNESCAPED_UNICODE); 16 17print_r($out_json); 18file_put_contents('message.json', $out_json, LOCK_EX); 19?> 20</body>
現状のjson
json
1[{"hoge":"hoge"},{"hogehoge":"hogehoge"}]
理想のjson
json
1{"hoge":"hoge","hogehoge":"hogehoge"}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。