Skip to content

Instantly share code, notes, and snippets.

@paulusm
Last active March 4, 2016 14:15
Show Gist options
  • Save paulusm/9365520 to your computer and use it in GitHub Desktop.
Save paulusm/9365520 to your computer and use it in GitHub Desktop.
<?php
// Read in the existing comments
$contents = utf8_encode(file_get_contents("comments.json"));
// Convert from JSON format to an Array
$commentrecords = json_decode($contents, true);
//Add a new array item for the newly posted comment
$commentrecords[] = array("name" => strip_tags($_POST["name"]), "comment" => strip_tags($_POST["comment"]));
//Save everything back to the file
file_put_contents("comments.json", json_encode($commentrecords, JSON_PRETTY_PRINT), LOCK_EX);
//Redirect back to the form
header("Location: project.php");
die();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment