- file_get_contents: documentation ( source)
- preg_match_all: documentation ( source)
- date_default_timezone_set: documentation ( source)
- explode: documentation ( source)
- trim: documentation ( source)
<?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>';
}
}
}
}
?>