blob: 6d4fd4826bde1f45eb0f1d7ea1aa3e8ba450f584 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<?php
class Comment
{
function __construct(string $comment, string $postURL, string $username = 'Anonymous')
{
$this->timestamp = date('Y-m-d H:i:s');
$this->username = $username;
$this->comment = $comment;
$this->postURL = $postURL;
}
function saveComment(string $fileName)
{
if (file_exists($fileName)) {
$sourceData = file_get_contents($fileName);
$tempArray = json_decode($sourceData);
array_push($tempArray, $this);
$jsonData = json_encode($tempArray, JSON_PRETTY_PRINT);
file_put_contents($fileName, $jsonData);
} else {
die('Error: The ' . $fileName . ' file does not exist.');
}
}
}
|