Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
// Laad JSON-gegevens van het bestand
$json_data = file_get_contents('messages.json');
$messages = json_decode($json_data, true);
$htmlString = "";
$date = new DateTime();
// Loop through each message and add it to the htmlString
foreach ($messages as $message) {
$htmlString .= '<div class="message">';
$htmlString .= '<p class="kleur">' . $message['firstName'] . ' '. $message['lastName'] . '</p>';
$htmlString .= '<p>' . $message['message'] . '</p>';
// Check if an image is set for this message
if(isset($message["imagePath"])) {
// Image is set, add it to the message box
$htmlString .= '<img src="' . $message["imagePath"] . '" alt="Afbeelding bij bericht">';
}
$date->setTimestamp($message["timestamp"]);
$formattedDateTime = $date->format('Y-m-d H:i:s');
// Add the timestamp to the message box
$htmlString .= '<p class="tijd">' . $formattedDateTime . '</p>';
$htmlString .= '</div>';
}
// Now $htmlString contains all the HTML for the messages
// You can use it wherever you want, for example, echo it or assign it to a variable for later use
// echo $htmlString;
?>