Tuesday, 15 May 2012

JSON in This Format in PHP -



JSON in This Format in PHP -

i'm working on project needs add together json file after every form submission. goal json like:

{ "word0":[ "cheese", "burger" ], "word1":[ "sup", "boi" ], "word2":[ "nothin'", "much" ] }

but i'm not able add together json file afterwards.

edit: i'm thinking creating new file every form submission. improve option? (storage size isn't problem)

here's current code places json file:

$response['word' . $count] = array('word1' => $_post['firstrow'], 'word2' => $_post['secondrow']); file_put_contents("query.json", file_get_contents("query.json") . json_encode($response) . "\n");

well if have no problem storage size can new file every form submission.

but can create 1 big file via reading writing file.

$data = json_decode(file_get_contents("data.json"), true); $data["word3"] = array("i don't" , "know"); file_put_contents("data.json", json_encode($data));

if want save on io, can writing @ specific position via fseek.

$file = fopen("data.json", "c"); fseek($file, -5, seek_end); // 5 character end of file. fwrite($file, $newjsonarrayelement); fclose($file);

^^^^^^^^^^^^^^^^^^^^^^^^^

this illustration snipper, need calculate characters seek end , somehow generate new json.

php json

No comments:

Post a Comment