-2

尝试编写页面的一部分,当我们在广播 5a-10a MF 时显示流媒体播放器,并在我们不广播时显示其他内容。

这是我现在所拥有的,但它不起作用。我对 PHP 很陌生。谢谢!

<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>
4

3 回答 3

4

#1。

此语句将始终为 FALSE:

($current_time <= 5 && $current_time >= 10)

正确的:

($current_time < 5 || $current_time >= 10)

#2。

$current_time = date(G);$current_day = date(l);输出通知:

Notice:  Use of undefined constant G - assumed 'G' in ...
Notice:  Use of undefined constant l - assumed 'l' in ...

正确的:

$current_time = date('G');
$current_day = date('l');

#3。

此代码echo "<a href="linktoplayer.html"><img src=http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg></a>";还将输出 PARSE ERROR:

Parse error: syntax error, unexpected 'linktoplayer' (T_STRING), expecting ',' or ';' in ...

如果你想输出它,你必须在字符串中"转义:\

echo "<a href=\"linktoplayer.html\"><img src=\"http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg\"></a>";

'改用:

echo '<a href="linktoplayer.html"><img src="http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg"></a>';

图像的pssrc属性必须用"".

于 2012-09-26T21:54:08.053 回答
4

两件事情:

  1. 正如已经指出的那样,您的时间逻辑是关闭的。它应该是$current_time < 5 or $current_time >= 10)

  2. 当你给日期函数提供一些东西时,它必须是一个字符串。date(l)会抛出一个错误,因为它应该是date('l').

编辑:

如果你真的想对你的代码进行基准测试,你应该使用它,idate因为它返回一个整数。您的比较将如下所示:

$current_time = idate('H');
$current_day = idate('w');

if ($current_day === 0 || $current_day === 6 || 
    $current_time < 5 || $current_time >= 10) {
    echo "We’re live Monday – Friday mornings. Check back then.";
}
于 2012-09-26T21:55:25.397 回答
0

我认为您应该更改If语句结构,使其看起来像这样

IF (on-air) 
THEN DisplayPlayer() 
ELSE echo "message saying Off Air"

通过这样做,当您在线时有人试图访问该站点时,您可以更快地击中玩家。

这是一项优化,可以在您播出时加快加载时间。如果您停播,它将经过两个步骤。它只是取决于你想要更快的加载时间

除了@glavić 在他的回答中写的内容之外,还应该使用它。

于 2012-09-26T21:59:59.043 回答