Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $decoded = array();
- $file_name = "data/".date('y-m-d').".txt";
- //Retrieve the data from our text file.
- $fileContents = file_get_contents($file_name);
- //Convert the JSON string back into an array.
- $decoded = json_decode($fileContents, true);
- //Example array.
- $decoded[] = date("H:i:s");
- //Encode the array into a JSON string.
- $encodedString = json_encode($decoded);
- //Save the JSON string to a text file.
- file_put_contents($file_name, $encodedString);
- //The end result.
- var_dump($decoded);
Advertisement
Add Comment
Please, Sign In to add comment