我有一些基本代碼,可以從上一頁(yè)的表單中獲取結(jié)果,并將其編碼為文本文件。出于某種原因,它對(duì)其進(jìn)行了正確編碼,然后創(chuàng)建了一個(gè)只有空值的第二個(gè)數(shù)組。(每個(gè)數(shù)組中有相同數(shù)量的值)老實(shí)說(shuō),我不知道是什么原因造成的。這是編碼代碼:<?php$name = $_POST['name'];$email = $_POST['email'];$date = $_POST['date'];$destination = $_POST['destination'];$msg = $_POST['msg'];//TODO the file write here VV, use 'a' instead of 'w' too ADD to the file instead of REWRITING IT.$arr = [$name,$email,$date,$destination,$msg];$write = json_encode($arr);echo $write;$file = fopen('data.txt', 'a');fwrite($file, $write);fclose($file);// echo $arr[]; ?>這是 .txt 文件中的結(jié)果:["Simon","example@example.com","0101-01-01T01:01","Ohio","Message here"][null,null,null,null,null](如果有幫助,它將它們寫(xiě)在同一行上)我不想要這個(gè)空數(shù)組,因?yàn)樗鼤?huì)搞亂我需要做的一些事情。有什么想法嗎
2 回答

縹緲止盈
TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
問(wèn)題不在于 json_encode。您收到兩個(gè)單獨(dú)的 POST 請(qǐng)求 - 一個(gè)具有正確的數(shù)據(jù),隨后的沒(méi)有任何數(shù)據(jù)的請(qǐng)求作為空值附加到文件中。您需要在客戶端調(diào)試為什么要發(fā)送兩個(gè)請(qǐng)求
- 2 回答
- 0 關(guān)注
- 141 瀏覽
添加回答
舉報(bào)
0/150
提交
取消