Created
April 28, 2017 15:47
-
-
Save bmoren/dcf7776f57443f09d826f44ece63b5a3 to your computer and use it in GitHub Desktop.
append a json object to an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$elements = json_encode( $_POST['data'],JSON_NUMERIC_CHECK ) . ','; | |
openlog("myScriptLog", LOG_PID | LOG_PERROR, LOG_LOCAL0); | |
syslog(LOG_INFO, $elements); | |
// $test = "{ | |
// lat: 000, | |
// lng: 000, | |
// story: 'test', | |
// username: 'test' | |
// },"; | |
$myfile = fopen("messages.js", "r") or die("Unable to open file!"); | |
$contents = fread($myfile,filesize("messages.js")); | |
fclose($myfile); | |
$myfile2 = fopen("messages.js", "w") or die("Unable to open file!"); | |
$contents = rtrim($contents, "]"); | |
// echo $contents; | |
$contents = $contents . $elements . "]"; | |
// echo $contents; | |
fwrite($myfile2,$contents); | |
fclose($myfile2); | |
// file_put_contents('messages.js', $elements, FILE_APPEND | LOCK_EX); | |
// echo "appended to JSON"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment