the actual json txt file content is similar to this:
[
{ "name": "Video 0", "comment": "3RtYLZaUUdU" },
{ "name": "Video 1", "comment" : "QrIGoya6BcE" },
{ "name":"Video 2", "comment": "KQbr2OGydJU" }
]
;
<pre>$post_data = $_POST['data']; //user comment input text
$file = "newfile.txt"; //actual json text file, the content is above
$content = file_get_contents($file);
$arr =(json_decode($content, true)); //converts json to php associative array
print_r($arr);
echo "<br><br>";
$AssArr =array(
"name" => "Video 3",
"comment" => $post_data, );
array_push($arr, $AssArr);
print_r($arr);
$json = json_encode($arr);// converts php associative array to json format
file_put_contents($file, $json);
echo "successfull";
all arrays saved onto json text file on one Line,
[{"name":"Video 0","comment":"3RtYLZaUUdU"},{"name":"Video 1","comment":"QrIGoya6BcE"},{"name":"Video 2","comment":"KQbr2OGydJU"},{"name":"Video 3","comment":"bad movie, hate that sh*t."},{"name":"Video 3","comment":"REMOVE THIS MOVE"},{"name":"Video 3","comment":"nooooooooooooooo"},{"name":"Video 3","comment":"BAD movie"}]
how to save them on json text file in separate lines like each array comes in separate line, thanks for your advice and help in advance
php associative array is written on long line in json file, my task is to have these arrays to be written on separate lines in json file, please help, i tried to add linebreaks like backslash r and backslash n with double quotes and dot, nope not worked, if anyone has expereince in such problem please share your knowledge, thanks lot.
What I have tried:
php associative array is written on long line in json file, my task is to have these arrays to be written on separate lines in json file, please help, i tried to add linebreaks like backslash r and backslash n with double quotes and dot, nope not worked, if anyone has expereince in such problem please share your knowledge, thanks lot.