Trying to write part of a page that would display a streaming player when we are on the air 5a-10a M-F and display something else when we aren’t on the air.
Here’s what I have right now, but it’s not working. I’m pretty new at PHP. Thanks!
<html>
<head>
<title>streaming</title>
</head>
<body>
<?php
//Get the current hour
$current_time = date(G);
//Get the current day
$current_day = date(l);
//Off air
if ($current_day == "Saturday" or $current_day == "Sunday" or ($current_time <= 5 && $current_time >= 10)) {
echo "We’re live Monday – Friday mornings. Check back then.";
}
// Display player
else {
echo "<a href="linktoplayer.html"><img src=http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg></a>";
}
?>
</body>
</html>
Two things:
As has been pointed out, your time logic is off. It should be
$current_time < 5 or $current_time >= 10)When you give something to the date function, it has to be a string.
date(l)will throw an error because it’s supposed to bedate('l').EDIT:
If you really want to benchmark your code, you should use
idateinstead since it returns an integer. Your comparisons would then be as follows: