3v4l.org

run code in 300+ PHP versions simultaneously
<?php function open_closed_message() { date_default_timezone_set('America/Toronto'); $date = new DateTime; echo date("D m/d/y h:i:s ",time()); $times = array( 'mon' => '9:00 AM - 9:00 PM', 'tue' => '9:00 AM - 9:00 PM', 'wed' => '9:00 AM - 9:00 PM', 'thu' => '9:00 AM - 9:00 PM', 'fri' => '9:00 AM - 9:00 PM', 'sat' => '11:00 AM - 6:00 PM', 'sun' => 'closed' ); function compileHours($times, $timestamp) { $times = $times[strtolower(date('D',$timestamp))]; if(!strpos($times, '-')) return array(); $hours = explode(",", $times); $hours = array_map('explode', array_pad(array(),count($hours),'-'), $hours); $hours = array_map('array_map', array_pad(array(),count($hours),'strtotime'), $hours, array_pad(array(),count($hours),array_pad(array(),2,$timestamp))); end($hours); if ($hours[key($hours)][0] > $hours[key($hours)][1]) $hours[key($hours)][1] = strtotime('+1 day', $hours[key($hours)][1]); return $hours; } function isOpen($now, $times) { $open = 0; // time until closing in seconds or 0 if closed // merge opening hours of today and the day before $hours = array_merge(compileHours($times, strtotime('yesterday',$now)),compileHours($times, $now)); foreach ($hours as $h) { if ($now >= $h[0] and $now < $h[1]) { $open = $h[1] - $now; return $open; } } return $open; } $now = time(); $open = isOpen($now, $times); if ($open == 0) { echo "Closed - Sorry, we are not making deliveries."; } elseif ($open <= 1800) { $tomorrow = strtotime('tomorrow', $now); if (date('N', $tomorrow) == 7) { $tomorrow = strtotime('next monday', $now); } $day = strtolower(date('D', $tomorrow)); $tomorrow = date('l', $tomorrow); $opentime = preg_replace('/^(\d+:\d+ [AP]M).*/', '$1', $times[$day]); echo "Finishing up current orders. We re-open $tomorrow at $opentime"; } else { echo "Open - Yes, we are making deliveries."; } } open_closed_message();
Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.23, 7.4.0 - 7.4.11
Mon 10/05/20 03:17:36 Closed - Sorry, we are not making deliveries.
Output for 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/0ABL6 on line 6
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function date_default_timezone_set() in /in/0ABL6 on line 5
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: date_default_timezone_set() in /in/0ABL6 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: date_default_timezone_set() in /in/0ABL6 on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: date_default_timezone_set() in /in/0ABL6 on line 5