<?php
$filename = "messages.txt";
if (file_exists($filename)) {
    $messages = file($filename, FILE_IGNORE_NEW_LINES);
    foreach ($messages as $message) {
        list($user, $text) = explode("-", $message, 2);
        $class = trim($user) === "User1" ? "user1" : "user2";
        echo "<div class='message $class'>$text</div>";
    }
}
?>
