3v4l.org

run code in 300+ PHP versions simultaneously
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Turn off chat button if before/after hours</title> <meta name="description" content="untitled"> <meta name="author" content="Craig MacKinnon"> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> function offMode() { jQuery(".initChat").addClass("offline"); jQuery(".initChat").removeAttr("onclick"); } </script> <style> * { margin:0; font: normal 12px sans-serif; } .initChat { background: url(http://i.snag.gy/DIPT4.jpg) no-repeat top left; display: block; height: 111px; width: 32px; position: fixed; top: 70%; z-index: 99999; } .initChat:hover { background-position: -34px 0px; cursor: pointer; } .initChat.offline { background-position: -68px 0px; cursor: context-menu; } </style> </head> <body> <?php // set timezone to Eastern Time date_default_timezone_set('America/New_York'); $storeSchedule = [ 'Sun' => ['closed'], 'Mon' => ['09:00 AM' => '05:00 PM'], 'Tue' => ['09:00 AM' => '05:00 PM'], 'Wed' => ['09:00 AM' => '05:00 PM'], 'Thu' => ['09:00 AM' => '05:00 PM'], 'Fri' => ['09:00 AM' => '05:00 PM'], 'Sat' => ['closed'] ]; // current or user supplied UNIX timestamp $timestamp = time(); // default status $status = 'open'; // get current time object $currentTime = (new DateTime())->setTimestamp($timestamp); // loop through time ranges for current day foreach ($storeSchedule[date('D', $timestamp)] as $startTime => $endTime) { // create time objects from start/end times $startTime = DateTime::createFromFormat('h:i A', $startTime); $endTime = DateTime::createFromFormat('h:i A', $endTime); // check if current time is within a range if (($currentTime < $startTime) && ($currentTime > $endTime)) { $status = 'closed'; echo '<script>jQuery(function() { offMode(); });</script>'; break; } } echo "We are currently: $status"; echo "<br />"; echo "Server time: " . date('h:i A'); ?> <a class="initChat" onclick="window.open('https://admin.instantservice.com/links/7565/61447', 'custclient', 'width=612,height=380,scrollbars=0'); return false;"></a> </body> </html>
Output for 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.25, 7.3.0 - 7.3.12, 7.4.0
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Turn off chat button if before/after hours</title> <meta name="description" content="untitled"> <meta name="author" content="Craig MacKinnon"> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> function offMode() { jQuery(".initChat").addClass("offline"); jQuery(".initChat").removeAttr("onclick"); } </script> <style> * { margin:0; font: normal 12px sans-serif; } .initChat { background: url(http://i.snag.gy/DIPT4.jpg) no-repeat top left; display: block; height: 111px; width: 32px; position: fixed; top: 70%; z-index: 99999; } .initChat:hover { background-position: -34px 0px; cursor: pointer; } .initChat.offline { background-position: -68px 0px; cursor: context-menu; } </style> </head> <body> We are currently: open<br />Server time: 01:25 PM <a class="initChat" onclick="window.open('https://admin.instantservice.com/links/7565/61447', 'custclient', 'width=612,height=380,scrollbars=0'); return false;"></a> </body> </html>
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/fhWnX on line 51
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/fhWnX on line 51
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/fhWnX on line 51
Process exited with code 255.

preferences:
204.51 ms | 401 KiB | 322 Q