D
D
d_h_o_l2017-04-24 14:54:39
PHP
d_h_o_l, 2017-04-24 14:54:39

How to make a line break when writing to json through php?

there is a code for writing to json file

$file = file_get_contents('informationJson/usersStatistics.json');
        $taskList = json_decode($file,TRUE);
        $taskList[] = array('name'=>$user->data->username,
                            'follows'=>$user->data->counts->follows,
                            'followed_by'=>$user->data->counts->followed_by,
                            'media'=>$user->data->counts->media,
                            'images'=>$col_images,
                            'video'=>$col_video,
                            'likes'=>$col_likes,
                            'likes_images'=>$col_likes_images,
                            'likes_video'=>$col_likes_video,
                            'comments'=>$col_comments,
                            'comments_images'=>$col_comments_images,
                            'comments_video'=>$col_comments_video,
                            'likes'=>$col_likes,
                            );
        file_put_contents('informationJson/usersStatistics.json',json_encode($taskList));

here is the output result
[{"name":"users181","follows":8,"followed_by":3,"media":5,"images":4,"video":1,"likes":8,"likes_images":7,"likes_video":1,"comments":1,"comments_images":1,"comments_video":0{"name":"users182","follows":8,"followed_by":3,"media":5,"images":4,"video":1,"likes":11,"likes_images":7,"likes_video":4,"comments":4,"comments_images":1,"comments_video":3}]

how to make it display in json file
[{
       "name":"users181",
       "follows":8,
       "followed_by":3,
       "media":5,
       "images":4,
       "video":1,
       "likes":8,
       "likes_images":7,
       "likes_video":1,
       "comments":1,
       "comments_images":1,
       "comments_video":0
}
{
       "name":"users182",
       "follows":5,
       "followed_by":3,
       "media":5,
       "images":4,
       "video":1,
       "likes":11,
       "likes_images":7,
       "likes_video":4,
       "comments":4,
       "comments_images":1,
       "comments_video":3
}]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question