3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('UTC'); $currentDateTime = new DateTime(); $url = 'https://www.lmsal.com/hek/hcr?cmd=view-planned-events&instrument=iris'; $content = file_get_contents($url); $dom = new DOMDocument(); @$dom->loadHTML($content); $table = $dom->getElementsByTagName('table')->item(0); $rows = $table->getElementsByTagName('tr'); foreach($rows as $row) { $columns = $row->getElementsByTagName('td'); if ($columns->length > 0) { $dateTimeRange = $columns->item(0)->nodeValue; // Match the pattern "YYYY-MM-DD HH:MM:SS - HH:MM:SS" and store the matches in $matches array preg_match_all('/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}-\d{2}:\d{2}:\d{2}/', $dateTimeRange, $matches); foreach ($matches[0] as $match) { list($start, $end) = explode("-", $match); $startDateTime = DateTime::createFromFormat('Y-m-d H:i:s', trim($start)); $endDateTime = DateTime::createFromFormat('Y-m-d H:i:s', trim($end)); // If the current time is within the start and end times, print it out if ($startDateTime <= $currentDateTime && $currentDateTime <= $endDateTime) { echo $match . '<br>'; } } } } ?>

preferences:
39.12 ms | 402 KiB | 5 Q