How can PHP be used to read dates from a text file and compare them with the current date for event scheduling purposes?

To read dates from a text file and compare them with the current date for event scheduling purposes, you can use PHP to read the file line by line, parse the dates, and compare them with the current date using the DateTime class. By comparing the dates, you can determine if an event is upcoming or has passed based on the current date.

<?php
$currentDate = new DateTime();
$file = fopen("dates.txt", "r");

while (!feof($file)) {
    $line = fgets($file);
    $eventDate = new DateTime(trim($line));

    if ($eventDate > $currentDate) {
        echo "Event scheduled for " . $eventDate->format('Y-m-d') . " is upcoming.\n";
    } else {
        echo "Event scheduled for " . $eventDate->format('Y-m-d') . " has passed.\n";
    }
}

fclose($file);
?>